From: João on 11 Jan 2010 09:00 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=22541&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)
From: João on 12 Jan 2010 13:38 Someone please?
From: r0g on 12 Jan 2010 15:05 Jo�o wrote: > Someone please? Haven't seen your original post yet mate, usenet can be flaky like that, might have been a good idea to quote your original post! Roger.
From: João on 12 Jan 2010 15:11 On Jan 12, 8:05 pm, r0g <aioe....(a)technicalbloke.com> wrote: > João wrote: > > Someone please? > > Haven't seen your original post yet mate, usenet can be flaky like that, > might have been a good idea to quote your original post! > > Roger. Thanks Roger. > João wrote: > > Someone please? > > Hi. > > I'm trying to figure out how to force URLencoding in my Python 2.4.3 > > environment, receiving data as 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=22541&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)
From: r0g on 12 Jan 2010 17:07 João wrote: > On Jan 12, 8:05 pm, r0g <aioe....(a)technicalbloke.com> wrote: >> João wrote: >>> Someone please? >> Haven't seen your original post yet mate, usenet can be flaky like that, >> might have been a good idea to quote your original post! >> >> Roger. > > Thanks Roger. > >> João wrote: >>> Someone please? >>> Hi. >>> I'm trying to figure out how to force URLencoding in my Python 2.4.3 >>> environment, receiving data as an input argument but I'm really at a loss >>> here. > >>> What am I doing wrong? > headers = { 'User-Agent' : user_agent } Those quotes need to be either " or ' i.e. headers = { 'User-Agent' : user_agent } If that doesn't sort it then it would be helpful to see a traceback or, if it is not crashing, get a description of how it is failing to do what you expect. Cheers, Roger.
|
Next
|
Last
Pages: 1 2 3 Prev: setTextAlignment function Qtablewidget PyQt Next: pyserial: Unexpected Local Echo |