Requests.post导致“ TooManyRedirects”错误

时间:2018-07-10 21:02:32

标签: python-3.x python-requests

试图执行以下代码,但始终会出现“ TooManyRedirects”错误。我在做什么错?

我的代码:

T (*f[N])(); // f is an array of pointers to functions returning T
T (*a())[N]; // a is a function returning a pointer to an array of T

这是我收到的大量错误消息:

import requests, json
Address = '100 W Grant Street'
City = 'Orlando'
State = 'FL'
url = 'https://tools.usps.com/tools/app/ziplookup/zipByAddress'
data = {'company':'', 'address1': Address, 'address2':'','city': City, 'state': 'State', 'zip': ''}
raw = requests.post(url, data=data)

1 个答案:

答案 0 :(得分:0)

由于某种原因,这个特定的url希望我也将headers ['User-Agent']包含在request.post语句中。然后我得到一个适当的答复。所以这是新代码:

import requests

s = requests.Session()
url = 'https://tools.usps.com/tools/app/ziplookup/zipByAddress'
payload = {'companyName':'', 'address1':'10570 Main St', 'address2':'', 'city':'Fairfax', 'state':'VA', 'zip':''}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
r = s.post(url, data = payload, headers = headers)