Python请求+;代理+;302重定向,为什么请求不正确?

Python请求+;代理+;302重定向,为什么请求不正确?,python,proxy,python-requests,httprequest,http-status-code-302,Python,Proxy,Python Requests,Httprequest,Http Status Code 302,我使用Python请求,并通过代理发送请求。我向其发送请求的站点具有302重定向,请求无法正常工作。似乎请求发送时没有代理,站点发现了我的真实IP Python代码: try: session = Session() request = Request('GET', url, headers=headers) prepped = session.prepare_request(request) resp = session.send(prepped, proxie

我使用Python请求,并通过代理发送请求。我向其发送请求的站点具有302重定向,请求无法正常工作。似乎请求发送时没有代理,站点发现了我的真实IP

Python代码:

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 [302]>

基本上,我需要从另一个IP发送请求,每次作为一个新用户使用新的cookie等等。 但有了这段代码,我无法做到这一点。
有人能帮我解决这个问题吗?

你可以使用请求。首先点击获取重定向url


r=requests.head(url,allow\u redirects=True)
打印(r.url)

代理
参数应该是“到代理URL的字典映射协议”()

:

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}