Amazon.com returns status 503

Viewed 998

I am trying to get https://www.amazon.com content with Python Requests library. But I got an server error instantly. Here is the code:

import requests

response = requests.get('https://www.amazon.com')
print(response)

And this code returns <Response [503]>. Anyone can tell me why is this happening and how to fix this?

3 Answers

Amazon requires, that you specify User-Agent HTTP header to return 200 response:

import requests

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0'}
response = requests.get('https://www.amazon.com', headers=headers)
print(response)

Prints:

<Response [200]>

Try this,

import requests


headers = {'User-Agent': 'Mozilla 5.0'}
response = requests.get('https://www.amazon.com', headers=headers)
print(response)

You have not put the code from which you want the info. The code should be like this:

import requests

response = requests.get('https://www.amazon.com')
print(response.content)

also you can use json, status_code or text in place of content

Related