force URLencoding script

r0g aioe.org at technicalbloke.com
Thu Jan 14 18:58:46 CET 2010


João wrote:
> On Jan 12, 10:07 pm, r0g <aioe.... at technicalbloke.com> wrote:
>> João wrote:
> 
> for the following data,
> authentication = "UID=somestring&"
> message = 'PROBLEM severity High: OperatorX Plat1(locationY) global
> Succ. : 94.470000%'
> dest_number = 'XXXXXXXXXXX'
> 
> url_values = urlencode({'M':message})
> enc_data = authentication + url_values + dest_number
> 
> 
> I'm getting null for
> full_url = Request(url, enc_data, headers)
> 
> and thus,
> response = urlopen(full_url).read()
> returns,
> TypeError: <exceptions.TypeError instance at 0x2b4d88ec6440>
> 
> )


Are you sure it's returning a null and not just some other unexpected
type?

I think your problem may be that you are passing a urllib2 class to
urllib(1)'s urlopen. Try using urllib2's urlopen instead e.g.

import urllib2
request_object = urllib2.Request('http://www.example.com')
response = urllib2.urlopen(request_object)
the_page = response.read()

Roger.



More information about the Python-list mailing list