-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use requests instead of urllib2 #18
Conversation
This has the benefit of not raising an exception for 404s.
Cool! Would you mind adding the requests library as a dependency in both setup.py and requirements.txt? |
Yep, done. |
Does this patch work for you? I receive the error "HTTP Error 400. The request has an invalid header name." Please check. I believe you need to use "User-Agent" instead of "User-agent" |
That's strange; I've tested it and it works for me. Does changing it to "User-Agent" fix it for you? Maybe we have different versions of |
I did this PR here: #23 Abandoned because I also added some gratuitous changes. Anyway. Yes, use User-Agent. |
This doesn't make a difference for me, but might for other people.
Ok, I made the change from User-agent to User-Agent. Just to be clear, are @gleitz and @hughdbrown getting Python exceptions with the text "HTTP Error 400" when using "User-agent"? I can't reproduce the error, even if I purposely omit the header . In that case, I merely get a version of the google results page for which |
Allowing that I have a slightly broken/non-standard howdoi, try this with my repo:
You will find the first four work in a standard way and the last four all fail. The only difference is the change of User-Agent to User-agent. Here is my pip freeze:
|
I am also on requests==1.0.4. Seems 0.13.3 is very old. On Wed, Jan 9, 2013 at 8:10 PM, Hugh Brown notifications@github.com wrote:
|
@gleitz Ah, that solves the mystery. After updating |
Using requests instead of urllib2 will prevent an exception from being raised in the case of a 404. For example, this fixes #16.
I also added some minor pep8 whitespace changes.