Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open site with urllib

Status
Not open for further replies.

simian336

Programmer
Sep 16, 2009
723
US
Hey all,

Kinda new to python. Trying to use urllib to read a website. The problem is the site I need to read contains single quotes in the url like
[ignore]
status)
[/ignore]
I have tried to encode the single quotes with unquote but it fails?

[ignore]
import urllib.request
import urllib.parse
x='x=x+urllib.parse.unquote('%27user%27,%27pw%27,%27mysid%27,?int status)')
print(x) #x looks correct at this point

v= urllib.request.urlopen(x)
print(v.read())
[/ignore]


raceback (most recent call last):
File "C:\Program Files\python33\url_test.py", line 9, in <module>
v= urllib.request.urlopen(x)
File "C:\Program Files\python33\lib\urllib\request.py", line 160, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\python33\lib\urllib\request.py", line 479, in open
response = meth(req, response)
File "C:\Program Files\python33\lib\urllib\request.py", line 591, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Program Files\python33\lib\urllib\request.py", line 517, in error
return self._call_chain(*args)
File "C:\Program Files\python33\lib\urllib\request.py", line 451, in _call_chain
result = func(*args)
File "C:\Program Files\python33\lib\urllib\request.py", line 599, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

Any ideas

Thanks Simian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top