授权标题从Docker Container中的请求中删除

时间:2018-03-07 17:21:29

标签: python docker http-headers python-requests urllib

我有一个python 3.x应用程序,它使用requests向API提交数据。 API需要Authorization标头。相关代码看起来像这样:

the_headers = {'Authorization': auth_header_token}
response = requests.post(
   the_url,
   json=the_data,
   headers=the_headers
)

在服务器或客户端计算机上运行时工作正常。

但是当我从Docker容器运行它时,我收到bad authorization header错误。

在这两种情况下,我得到以下输出:

print(res.request.headers)
{
  'User-Agent': 'python-requests/2.18.4', 
  'Accept-Encoding': 'gzip, deflate', 
  'Accept': '*/*', 
  'Connection': 'keep-alive', 
  'Authorization': 'auth_header_token', 
  'Content-Length': '2984', 
  'Content-Type': 'application/json'
}

但支持API的团队告诉我,我的失败请求不包含Auth标头

好请求:

{ 
    'x-ssl': 'on',
    host: 'ip1:port1',
    connection: 'close',
    'content-length': '2984',
    accept: '*/*',
    'accept-encoding': 'gzip, deflate',
    authorization: 'auth_header_token',
    'content-type': 'application/json',
    'user-agent': 'python-requests/2.18.4',
    'x-forwarded-for': 'ip2',
    'x-forwarded-port': 'port2',
    'x-forwarded-proto': 'https' 
}

错误请求:

{ 
    'x-ssl': 'on',
    host: 'ip1:port1',
    connection: 'close',
    'content-length': '2984',
    accept: '*/*',
    'accept-encoding': 'gzip, deflate',
    'content-type': 'application/json',
    'user-agent': 'python-requests/2.18.4',
    'x-forwarded-for': 'ip3',
    'x-forwarded-port': 'port2',
    'x-forwarded-proto': 'https' 
}

我原本以为这个问题可能与Github Session's Authorization header isn't sent on redirect上的问题有关,但这两个请求在接收端都有x-forwarded-for,所以现在我不太确定。< / p>

相同的代码库,只有更改的是运行时环境(MacOS与在MacOS上运行的Docker容器)。

0 个答案:

没有答案
相关问题