?
Solved

convert list item to string. or...

Posted on 2010-11-27
3
Medium Priority
?
1,041 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
markoilic earned 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

"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 …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

770 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