I'm using Python requests and I send requests through a proxy. The site I'm sending requests to has 302 redirection, and the request doesn't work properly. It seems that the request sends without proxy and the site finds out my real IP.
Python code:
try:
session = Session()
request = Request('GET', url, headers=headers)
prepped = session.prepare_request(request)
resp = session.send(prepped, proxies=proxy, timeout=8)
session.cookies.clear()
print(resp.status_code)
print(resp.history)
except requests.exceptions.Timeout:
print("Timeout error ... :( " + "\n")
except requests.exceptions.ConnectionError:
print("Connection error ... :( " + "\n")
except requests.exceptions.HTTPError:
print("HTTPError ... :( " + "\n")
Response history
<Response [302]>
Basically I need to send request from another IP and every time as a new user with new cookies and so on. But with this code I can't manage to do it. Can someone help me with this and say what's the problem?
You can using requests.head to get redirected url first.
r = requests.head(url, allow_redirects=True)
print(r.url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With