0

I am unable to remove default headers sent by Python requests.

These are the default headers which python requests is sending:

User-Agent: python-requests/2.24.0
Accept-Encoding: gzip, deflate
Accept: application/json
Connection: keep-alive

here is my code:

    import requests

url = ('http://google.com')
headers = {
    'Accept': 'application/json',
    'Host': 'google.com'
    }
for num_of_res in range(1,10):
    print(num_of_res)
response = requests.get((url.format(num_of_res)), headers=headers, verify= False)
coffee
  • 1
  • 3
  • 2
    Does this answer your question? [Sending "User-agent" using Requests library in Python](https://stackoverflow.com/questions/10606133/sending-user-agent-using-requests-library-in-python) – The Pjot Aug 31 '20 at 09:52
  • @ThePjot No. I only want to send 'Accept and Host' in headers – coffee Aug 31 '20 at 09:56
  • Yes, and you have to override user-agent if you want to get rid of it :) – The Pjot Aug 31 '20 at 10:02
  • Like How? I can set user-agent value to none, but its still sending "user-agent : none" instead of removing user-agent field – coffee Aug 31 '20 at 10:05
  • Perhaps setting it to a empty string? Why wouldn't you want a user-agent to begin with really? Just put some jibberish or fake in it if so desired. – The Pjot Aug 31 '20 at 10:16
  • because the original program is not sending those headers fields, and server can detect I'm using python or some kind of tools – coffee Aug 31 '20 at 10:19

0 Answers0