Python Http Error 400 Bad Request
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business urllib2.httperror http error 400 bad request json Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Python 3 Urllib.error.httperror Http Error 400 Bad Request
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just http error 400: bad request python urllib like you, helping each other. Join them; it only takes a minute: Sign up HTTP Error 400: Bad Request (urllib) up vote 1 down vote favorite I'm writing a script to get information regarding buildings in NYC. I response 400 python requests know that my code works and returns what i'd like it to. I was previously doing manual entry and it worked. Now i'm trying to have it read addresses from a text file and access the website with that information and i'm getting this error: urllib.error.HTTPError: HTTP Error 400: Bad Request I believe it has something to do with the website not liking lots of access from something that isn't a browser. I've heard something
Raise Httperror(req.get_full_url(), Code, Msg, Hdrs, Fp)
about User Agents but don't know how to use them. Here is my code: from bs4 import BeautifulSoup import urllib.request f = open("FILE PATH GOES HERE") def getBuilding(link): r = urllib.request.urlopen(link).read() soup = BeautifulSoup(r, "html.parser") print(soup.find("b",text="KEYWORDS IM SEARCHING FOR GO HERE:").find_next("td").text) def main(): for line in f: num, name = line.split(" ", 1) newName = name.replace(" ", "+") link = "LINK GOES HERE (constructed from num and newName variables)" getBuilding(link) f.close() if __name__ == "__main__": main() python beautifulsoup urllib share|improve this question asked Jun 18 at 19:17 Harrison 1,219319 The fact that you've run the code in isolation makes me doubt the server is stopping the request based on solely on your User Agent. More likely is that is rate limiting your client or a bug in how you've constructed your request... can you please put the real code in for your link and a sample line from your file? –Peter Brittain Jun 18 at 22:34 I'll get back to you with that tomorrow morning! –Harrison Jun 19 at 3:42 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote A 400 error means that the server cannot understand your request (e.g., malformed syntax). That said, its up to the developers on what status code they want to return and, unfortunately, not everyone strictly f
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss urllib2.httperror: http error 403: forbidden the workings and policies of this site About Us Learn more about requests post python Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Python Requests Example
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each http://stackoverflow.com/questions/37900758/http-error-400-bad-request-urllib other. Join them; it only 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 questions you might have Meta http://stackoverflow.com/questions/20144366/httperror-http-error-400-bad-request-urllib2 Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack https://github.com/sendgrid/sendgrid-python/issues/187 Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, http error helping each other. Join them; it only takes a minute: Sign up HTTPError: HTTP Error 400: Bad request urllib2 up vote 1 down vote favorite 1 I am beginner to python. I am the developer of Easy APIs Project (http://gcdc2013-easyapisproject.appspot.com) and was doing a Python implementation of weather API using my project. Visit http://gcdc2013-easyapisproject.appspot.com/APIs_Doc.html to see Weather http error 400 API. The below is my implementation but it returns HTTPError: HTTP Error 400: Bad request error. import urllib2 def celsius(a): responsex = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/unitconversion?q='+a+' in celsius') htmlx = responsex.read() responsex.close() htmlx = html[1:] #remove first { htmlx = html[:-1] #remove last } htmlx = html.split('}{') #split and put each resutls to array return str(htmlx[1]); print "Enter a city name:", q = raw_input() #get word from user response = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/weather?q='+q) html = response.read() response.close() html = html[1:] #remove first { html = html[:-1] #remove last } html = html.split('}{') #split and put each resutls to array print "Today weather is " + html[1] print "Temperature is " + html[3] print "Temperature is " + celsius(html[3]) Please help me.. python urllib2 share|improve this question asked Nov 22 '13 at 11:56 Isham Mohamed 680520 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote accepted The query string should be quoted using urllib.quote or urllib.quote_plus: import urllib import urllib2 def celsius(a): responsex = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/unitconversion?q=' + urllib.quote(a + ' in celsius'
Sign in Pricing Blog Support Search GitHub This repository Watch 150 Star 312 Fork 145 sendgrid/sendgrid-python Code Issues 11 Pull requests 2 Projects 1 Pulse Graphs New issue SendGrid v3 with HTML - 400 Bad Request #187 Closed davey-dev opened this Issue Jul 4, 2016 · 7 comments Projects None yet Labels type: question Milestone No milestone Assignees No one assigned 3 participants davey-dev commented Jul 4, 2016 • edited Issue Summary I've been trying to migrate to v3 API and several of my emails to be sent get BadRequest responses that v2 does not give me (had to revert back). I believe that Json being created for the e-mail is bad as same as here: sendgrid/sendgrid-csharp#256 Technical details: sendgrid-python Version: 3.0.0 Python Version: 3.5.1+ 👍 1 exp0nge commented Jul 4, 2016 • edited I'm having the same error pop up for me while trying to use a template. Should I make another issue? Here's my code snippet: def send_welcome_email(user_email, user_name): """ Sends a thank you email :param user_email: str :param user_name: str :return: """ sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) from_email = sendgrid.Email(email=FROM_EMAIL, name='Me') to_email = sendgrid.Email(email=user_email, name=user_name) mail = Mail(from_email=from_email, subject='Welcome!', to_email=to_email) personalization = Personalization() personalization.add_substitution(Substitution(key=':name', value=user_name)) mail.add_personalization(personalization) mail.set_template_id(WELCOME_TEMPLATE_ID) response = sg.client.mail.send.post(request_body=mail.get()) print response SendGrid member thinkingserious commented Jul 4, 2016 @davey-dev, Could you please provide the code that you are having trouble with? Or at least the return value from mail.get()? Thanks! @exp0nge, When you use the Mail constructor, we build the personalization obje