E
E
Emil Revencu2015-10-29 00:53:03
Python
Emil Revencu, 2015-10-29 00:53:03

Where is the error with request python (I get status code = 400)?

import requests
url="http://www.booking.com/reviewlist.en-gb.html?pagename=quot-bielis-quot;cc1=xa"
page = requests.get(url) 
if page.status_code==200:
  print 'OK'
else:
  print 'error page code:',page.status_code

Why does the page load in the browser, but on PYTHON with requests.get I get the status 400?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2015-10-29
@Revencu

It's all about User-AgentTry this:

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
response = requests.get(url, headers=headers)

There is also such a thing . It is put like this: It
should work like this:
from fake_useragent import UserAgent
ua = UserAgent()
headers = {'User-Agent': ua.random}
response = requests.get(url, headers=headers)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question