Http Error 400 Bad Request Urllib2
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss urllib2.httperror http error 400 bad request json the workings and policies of this site About Us Learn more python 3 urllib.error.httperror http error 400 bad request about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow raise httperror(req.get_full_url(), code, msg, hdrs, fp) Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping
Http Error 400: Bad Request Python Urllib
each other. Join them; it only takes a minute: Sign up urllib2 HTTP Error 400: Bad Request up vote 12 down vote favorite 5 I have a piece of code like this host = 'http://www.bing.com/search?q=%s&go=&qs=n&sk=&sc=8-13&first=%s' % (query, page) req = urllib2.Request(host) req.add_header('User-Agent', User_Agent) response = urllib2.urlopen(req) and when I input a query greater than one word like "the response 400 python requests dog" i get the following error. response = urllib2.urlopen(req) File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 400, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 513, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 438, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 372, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 521, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 400: Bad Request Can anyone point out what im doing wrong? Thanks in advance. python urllib2 http-error share|improve this question asked Jan 12 '12 at 18:27 PyFan 66115 I've also received "urllib2.HTTPError: HTTP Error 406: Not Acceptable" when attempting to request URLs with whitespace. –jamesc Oct 5 '12 at 9:27 add a comment| 4 Answers 4 active oldest votes up vote 48 down vote accepted The reason that "the dog" returns a 400 Error is because you aren't escaping the string for a URL. If you do this: import urllib, urllib2 quoted_query = urllib.quote(query) host = 'http://www.bing.com/search?q=%s&go=&qs=n&sk
here for urllib2.httperror: http error 403: forbidden a quick overview of the site Help Center
Urllib2 Post
Detailed answers to any questions you might have Meta Discuss the workings
Python Requests Example
and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers http://stackoverflow.com/questions/8840303/urllib2-http-error-400-bad-request or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only http://stackoverflow.com/questions/28375665/urllib2-httperror-http-error-400-bad-request-python takes a minute: Sign up urllib2.HTTPError: HTTP Error 400: Bad Request - Python up vote 0 down vote favorite I'm trying to POST using urllib and urllib2 but it keeps giving me this error Traceback (most recent call last): File "/Users/BaDRaN/Desktop/untitled text.py", line 39, in
here for a quick overview of the site Help Center Detailed answers to any http://stackoverflow.com/questions/26894320/again-urllib-error-httperror-http-error-400-bad-request questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more https://www.biostars.org/p/7859/ about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack http error Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Again urllib.error.HTTPError: HTTP Error 400: Bad Request up vote 3 down vote favorite Hy! I tried to open web-page, that is normally opening in browser, but python just swears http error 400 and does not want to work. import urllib.request, urllib.error f = urllib.request.urlopen('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphire') And another way import urllib.request, urllib.error opener=urllib.request.build_opener() f=opener.open('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphi re') Both options give one type of error: Traceback (most recent call last): File "
faq • rss Community Log In Sign Up Add New Post Question: Why Posting Data To Plantcare With Urllib,Urllib2 In Python Returns 'Http Error 400: Bad Request' 3 5.5 years ago by Gahoo • 240 United States Gahoo • 240 wrote: I was tring to write a python script to get data from PlantCARE. But It alway return 'HTTP Error 400: Bad Request'. urllib and urllib2 works fine with other websites. Here're the codes. import urllib2, urllib url="http://bioinformatics.psb.ugent.be/webtools/plantcare/cgi-bin/CallMat_IE55.htpl" params={ 'Field_Sequence':'CTAATCTTATGCATTTAGCAGTACAAATTCAAAAATTTCCCATTTTTATTCATGAATCATACCATTATATATTAACTAAATCCAAGGTAAAAAAAAGGTATGAAAGCTCTATAGTAAGTAAAATATAAATTCCCCATAAGGAAAGGGCCAAGTCCACCAGGCAAGTAAAATGAGCAAGCACCACTCCACCATCACACAATTTCACTCATAGATAACGATAAGATTCATGGAATTATCTTCCACGTGGCATTATTCCAGCGGTTCAAGCCGATAAGGGTCTCAACACCTCTCCTTAGGCCTTTGTGGCCGTTACCAAGTAAAATTAACCTCACACATATCCACACTCAAAATCCAACGGTGTAGATCCTAGTCCACTTGAATCTCATGTATCCTAGACCCTCCGATCACTCCAAAGCTTGTTCTCATTGTTGTTATCATTATATATAGATGACCAAAGCACTAGACCAAACCTCAGTCACACAAAGAGTAAAGAAGAACAA', 'Field_SequenceName':'demo', 'Field_SequenceDate':'4.27', 'Mode':'readonly', 'StartAt':'0', 'NbRecs':'10', 'MatInspector':'Search' } data=urllib.urlencode(params) print urllib2.urlopen(url, data).read() But I can get the result page directly with curl. It's wierd! Open this link in any browser should be the same ,and it works fine. curl "http://bioinformatics.psb.ugent.be/webtools/plantcare/cgi-bin/CallMat_IE55.htpl?Mode=readonly&StartAt=0&Field_Sequence=CTAATCTTATGCATTTAGCAGTACAAATTCAAAAATTTCCCATTTTTATTCATGAATCATACCATTATATATTAACTAAATCCAAGGTAAAAAAAAGGTATGAAAGCTCTATAGTAAGTAAAATATAAATTCCCCATAAGGAAAGGGCCAAGTCCACCAGGCAAGTAAAATGAGCAAGCACCACTCCACCATCACACAATTTCACTCA