import requests
requests.get("http://www.sample.com")
How to modifiy the parameter to send the requests like below:
"GET www.sample.com HTTP/1.0"
"GET www.sample.com HTTP/1.1"
Try to pass a User-Agent string, like this:
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'}
URL = 'http://serveraddress'
page = requests.get(URL, headers=headers)
print(page.text)
Background: Working with a legacy Shoutcast streaming audio server, I was getting the following error:
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('ICY 200 OK\r\n'))
I noticed, too, that wget attempted to stream the data, even when given an -O output directive.
Comparing with Developer Tools in Chrome, I could see several request headers that the browser set, including User-Agent. I copied the User-Agent value from Chrome and used it as a parameter in a requests.get function.
headersto pass aUser-Agentstring, like this:headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'}- Rocky Raccoon