【发布时间】:2018-06-22 18:06:45
【问题描述】:
我想用客户端配置复制以下内容。
Curl -D- -X GET -H "Authorization: Basic ZnJlZDpmcmVk" -H "Content-Type: application/json" http://localhost:7990/rest/api/1.0/projects
https://developer.atlassian.com/server/bitbucket/how-tos/example-basic-authentication/
这是在私人仓库中下载用于更新 exe 的文件。
我在使用 bitbucket 时经常遇到 400 个错误。
我有什么:
client = Client(ClientConfig(), headers={'basic_auth':'U:P' }, refresh=True)
我想包含这个标题
header = {'Content-Type': 'application/json'}
比如:
client = Client(ClientConfig(), headers={'basic_auth': 'brofewfefwefewef:EKAXsWkdt5H6yJEmtexN'}, header = {'Content-Type': 'application/json'}, refresh=True)
应该修复吗?
至少根据....
“某些 http 客户端软件在发送授权标头之前希望收到身份验证质询,这可能意味着它可能无法按预期运行。在这种情况下,您可能需要将其配置为提供上述授权标头而不是依赖其默认机制。”
还有……
https://stackoverflow.com/questions/8840303/urllib2-http-error-400-bad-request
但对我来说,即使更改 400 https://pastebin.com/V9ibxTRX (此处为完整代码或以下简短版本),我总是会出错
可选的错误消息(它不漂亮,但我确实减少了它):
~~~~~ACCESSING PAGE AND FOUND!~~~
DEBUG:pyupdater.client.downloader:Url for request: https://api.bitbucket.org/2.0/repositories/Username/repository/downloads/keys.gz
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.bitbucket.org
send: b'GET /2.0/repositories/Username/repository/downloads/keys.gz HTTP/1.1\r\nHost: api.bitbucket.org\r\nAccept-Encoding: identity\r\nauthorization: Basic ywafdwafawffwawffawafwfwaawfawfg==\r\n\r\n'
reply: 'HTTP/1.1 302 Found\r\n'
~~~~~~RETRYING REDIRECTION PRESENT (IS THIS THE CAUSE OF ISSUES)??~~
DEBUG:urllib3.connectionpool:https://api.bitbucket.org:443 "GET /2.0/repositories/Username/repository/downloads/keys.gz HTTP/1.1" 302 0
DEBUG:urllib3.util.retry:Incremented Retry for (url='https://api.bitbucket.org/2.0/repositories/Username/repository/downloads/keys.gz'): Retry(total=2, connect=None, read=None, redirect=None, status=None)
INFO:urllib3.poolmanager:Redirecting https://api.bitbucket.org/2.0/repositories/Username/repository/downloads/keys.gz -> https://bbuseruploads.s3.amazonaws.com/a0e395b6-0c54-4efb-9074-57ec4190020b/downloads/1c87431a-98de-4d97-8c80-000243f81cba/keys.gz?Signature=FvA9X7K9ryM2Ft2mTV7PZefidJY%3D&Expires=1515817377&AWSAccessKeyId=AKIAIQWXW6WLXMB5QZAQ&versionId=6J830UBC1RFvWz.R6pMDwIiJQNKJjSkm&response-content-disposition=attachment%3B%20filename%3D%22keys.gz%22
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): bbuseruploads.s3.amazonaws.com
~~HEADERS MIGHT BE ISSUE ACCORDING TO DOCS https://developer.atlassian.com/server/bitbucket/how-tos/example-basic-authentication/~~
header: Server header: Vary header: Content-Type header: X-OAuth-Scopes header: Strict-Transport-Security header: Date header: Location header: X-Served-By header: ETag header: X-Static-Version header: X-Content-Type-Options header: X-Accepted-OAuth-Scopes header: X-Credential-Type header: X-Render-Time header: Connection header: X-Request-Count header: X-Frame-Options header: X-Version header: Content-Length send: b'GET /a0e395b6-0c54-4efb-9074-57ec4190020b/downloads/1c87431a-98de-4d97-8c80-000243f81cba/keys.gz?Signature=FvA9X7K9ryM2Ft2mTV7PZefidJY%3D&Expires=1515817377&AWSAccessKeyId=AKIAIQWXW6WLXMB5QZAQ&versionId=6J830UBC1RFvWz.R6pMDwIiJQNKJjSkm&response-content-disposition=attachment%3B%20filename%3D%22keys.gz%22 HTTP/1.1\r\nHost: bbuseruploads.s3.amazonaws.com\r\nAccept-Encoding: identity\r\nauthorization: Basic YnJvZmV3ZmVmd2VmZXdlZjpFS0FYc1drZHQ1SDZ5SkVtdGV4Tg==\r\n\r\n'
DEBUG:urllib3.connectionpool:https://bbuseruploads.s3.amazonaws.com:443 "GET /a0e395b6-0c54-4efb-9074-57ec4190020b/downloads/1c87431a-98de-4d97-8c80-000243f81cba/keys.gz?
Signature=FvA9X7K9ryM2Ft2mTV7PZefidJY%3D&Expires=1515817377&AWSAccessKeyId=AKIAIQWXW6WLXMB5QZAQ&versionId=6J830UBC1RFvWz.R6pMDwIiJQNKJjSkm&response-content-disposition=attachment%3B%20filename%3D%22keys.gz%22 HTTP/1.1" 400 None
~~UNABLE TO ACCESS PAGE (WAIT, BEFORE IT HAD 'HTTP/1.1 302 Found\r\n' SEE TOP)~~
reply: 'HTTP/1.1 400 Bad Request\r\n'
DEBUG:pyupdater.client.downloader:Resource URL: https://api.bitbucket.org/2.0/repositories/Username/repository/downloads/keys.gz
DEBUG:pyupdater.client.downloader:Got content length of: None
DEBUG:pyupdater.client.downloader:Content-Length not in headers
DEBUG:pyupdater.client.downloader:Callbacks will not show time left or percent downloaded.
DEBUG:pyupdater.client.downloader:Using file as storage since the file is too large
【问题讨论】:
-
我非常怀疑您使用的是 urllib3 - urllib3 源代码中既没有
Client也没有ClientConfig类。可以发a complete example吗? -
@phihag 错误消息已满:pastebin.com/V9ibxTRX ctr find F -> 400 。如果你真的想重现,你可以,但需要 5 分钟以上。这里的工作示例。 stackoverflow.com/questions/48047296/… 第 366-368 行显示下载器使用 url lib github.com/JMSwag/PyUpdater/blob/master/pyupdater/client/… 引导您完成它的文档。 pyupdater.org/usage-cli 完成后,您会收到类似的错误。
-
@phihag 与其那样做,不如看看我从他们的文档中得到的例子。我认为用配置复制它应该可以解决。可悲的是,我一无所知,一整天都被困住了,但这很可能是如何解决的
-
抱歉,您提到的所有帖子都没有接近完成。此外,格式不适合:在这个问题中,您使用
auth初始化客户端,并将列表初始化为headers。在code you link to 中,Client 没有auth参数,headers接受一个字典,而不是一个列表。如果您希望任何人能够回答您的问题,则必须包含完整的代码;即可以粘贴到文件中并立即运行的代码。删除所有不必要的杂物。 -
@phihag 我已根据您向我解释的内容更新了问题。如果还是不对,就直说吧,我会澄清的
标签: python curl bitbucket urllib http-error