Solved

convert list item to string. or...

Posted on 2010-11-27
3
1,008 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now