Solved

convert list item to string. or...

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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…

688 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