Top products from r/inventwithpython
We found 4 product mentions on r/inventwithpython. We ranked the 3 resulting products by number of redditors who mentioned them. Here are the top 20.
We found 4 product mentions on r/inventwithpython. We ranked the 3 resulting products by number of redditors who mentioned them. Here are the top 20.
I believe the problem is not with your use of the
requests.raise_for_status()
method but rather with the website you've chosen. Amazon thinks you're a bot and it's not letting the request go through.​
HTTP headers allow clients/servers to send additional information to each other when making a request/response. You can trick the server into thinking you're using the site through a browser (and that you're not a bot) if you pass HTTP headers into the request.
This should work:
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0'}
request = requests.get("https://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994", headers=headers)
request.raise_for_status()
I pulled the headers from the Mozilla developer docs.
The syntax of a user-agent request header is essentially
<product>/<product version> <comments>
. So in the user-agent header I gave you, we have Mozilla (the product)/5.0 (the version number), and then a comment (about computer specs). Then we have two other product/product version pairs: Gecko/20100101 Firefox/50.0.​
Hope this helps :)
I'm thinking about this book as a next step http://www.amazon.co.uk/Python-Standard-Library-Example-Developers/dp/0321767349/ref=sr_1_1?ie=UTF8&qid=1418375089&sr=8-1&keywords=python+standard+library What do you think about that?
https://inventwithpython.com/blog/2019/10/07/whats-new-in-the-2nd-edition-of-automate-the-boring-stuff-with-python/ Right at the very bottom. I look forward to reading more from everyone! Has anyone else preordered the next book? Python Beyond the Basics