Solved

convert list item to string. or...

Posted on 2010-11-27
3
1,020 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:StolenMan
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
markoilic earned 500 total points
ID: 34222226
In this line you need to pass a dictionary

data = urllib.parse.urlencode({"email":"qwerty@yahoo.com"})

but in your case this line is not necesary

response = urllib.urlopen(url[0], url[1])

0
 
LVL 2

Expert Comment

by:markoilic
ID: 34222244
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)
0
 

Author Closing Comment

by:StolenMan
ID: 34224450
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
looping 11 39
Macports Import beautifulsoup4 Problem 6 84
BASH script to modify crontab? 3 95
Turning python script into an applet 12 123
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question