Kodi Community Forum
Python urllib.open issue - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Python urllib.open issue (/showthread.php?tid=108125)



Python urllib.open issue - xceph - 2011-08-19

Hello,

This is a pretty general Python question, but relates to the streaming app I am working on.

I have a url opener defined as such:

Code:
class BrowseBot:
    def __init__(self):
        cookie_handler= urllib2.HTTPCookieProcessor()
        redirect_handler= urllib2.HTTPRedirectHandler()
        self._opener = urllib2.build_opener(redirect_handler, cookie_handler)

    def GET(self, url):
        return self._opener.open(url).read()

    def POST(self, url, parameters):
        return self._opener.open(url, urllib.urlencode(parameters)).read()

I am trying to do a GET/POST on a url of the form "http://www.example.com/#/foo" however, the URL always truncates after the #. It prints to console fine, showing the full URL, but when intercepting the POST/GET I notice that it is truncated.

Can anyone provide insite to this issue?

(Its very hard to Google this since # = python comment!!! Sad )


- t0mm0 - 2011-08-19

xceph Wrote:Hello,

This is a pretty general Python question, but relates to the streaming app I am working on.

I have a url opener defined as such:

Code:
class BrowseBot:
    def __init__(self):
        cookie_handler= urllib2.HTTPCookieProcessor()
        redirect_handler= urllib2.HTTPRedirectHandler()
        self._opener = urllib2.build_opener(redirect_handler, cookie_handler)

    def GET(self, url):
        return self._opener.open(url).read()

    def POST(self, url, parameters):
        return self._opener.open(url, urllib.urlencode(parameters)).read()

I am trying to do a GET/POST on a url of the form "http://www.example.com/#/foo" however, the URL always truncates after the #. It prints to console fine, showing the full URL, but when intercepting the POST/GET I notice that it is truncated.

Can anyone provide insite to this issue?

(Its very hard to Google this since # = python comment!!! Sad )

surely "http://www.example.com/#/foo" is saying 'go to http://www.example.com/ and scroll to the anchor called '/foo'? so isn't that behaviour correct? (browsers behave this way too)

if what you really want to do is send '#' as part of a url you need to url encode it (it will become '%23'). you can use urllib.quote_plus() to do that.

t0mm0


- xceph - 2011-08-19

Thanks, that probably is the case. Not very familiar with web-techs, this is me getting my feet wet Smile