FAQ
Hi.
I'm trying to figure out how to force URLencoding in my Python 2.4.3
environment receiving data an input argument but I'm really at a loss
here.

What am I doing wrong?

#!/usr/bin/env python

import sys
from urllib import urlencode, urlopen
from urllib2 import Request
import urlparse

destination = sys.argv[1]
msg = sys.argv[2] #Will I have problems with this one if the input is
multiline?

# the browser identifies itself using the User-Agent header
# after creating the Request object, it's possible to pass in a
dictionary of headers
user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322)' # force the request to be identified as IE
5.5....
headers = { ?User-Agent? : user_agent }

# force no proxy

authentication = 'UID"541&PW=gdyb21LQTcIANtvYMT7QVQ==&'
# force Unicode display format
message = u'M=%s&' % msg
dest_number = 'N=%s' % destination
data = authentication + message + dest_number

url = 'http://10.112.28.221:38080/GwHTTPin/sendtext'
print 'Encoded URL:', url

#get full URL adding ? to it, followed by the encoded values
#full_url = url + '?' url_values
#should I force url_values = urllib.urlencode(data) instead?
full_url = urllib2.Request(url, data, headers)

response = urllib2.urlopen(full_url) #.urlopen works transparently
with proxies which do not require authentication

processed = urllib.open(full_url)

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 14 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedJan 11, '10 at 2:00p
activeJan 18, '10 at 8:50p
posts14
users2
websitepython.org

2 users in discussion

João: 9 posts R0g: 5 posts

People

Translate

site design / logo © 2022 Grokbase