Link to home
Start Free TrialLog in
Avatar of StolenMan
StolenMan

asked on

convert list item to string. or...

Hello.

I'm getting error "TypeError: not a valid non-string sequence or mapping object"
How to convert list item to string .. or another solution?
Python 3x.
url = "http://site.com/subscribe.php?email=qwerty@yahoo.com"
if method == "POST":
	urlOpener.addHeaders = [('Content-Type', 'application/x-www-form-urlencoded')]
	url = url.split("?")
	data = urllib.parse.urlencode(url[1])
	urlOpener.addHeaders = [('Content-Length', str(len(data)))]
	response = urllib.urlopen(url[0], data)
.
..
...
....

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of markoilic
markoilic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markoilic
markoilic

In tray to reconstruct your part of code and get this succesfuly run for me

method = "POST"

from urllib import parse
from urllib import request


urlOpener = request.build_opener( request.HTTPCookieProcessor() )

url = 'http://localhost/pytest.php?email=xyz@abc.com'


if method == "POST":
    urlOpener.addHeaders = [('Content-Type', 'application/x-www-form-urlencoded')]
    url = url.split("?")
    data = url[1]
    urlOpener.addHeaders = [('Content-Length', str(len(data)))]
    response = request.urlopen(url[0], data)
Avatar of StolenMan

ASKER

Thanks!