Python Citrix Sharefile 令牌请求给出 400 错误
我正在尝试发出一个简单的请求以从 Citrix ShareFile 获取访问令牌,但它抛出 400 错误。
我将完全按照文档中提到的方式进行操作,除了使用 HTTPLib 更改 Python2 代码,使用 Requests 更改 Python3 代码。代码是:
url = 'https://{my_domain}.sharefile.com/oauth/token'
headers = {'Content_Type': 'application/x-www-form-urlencoded'}
params = {'grant_type':'password', 'client_id':my_client_id, 'client_secret':my_client_secret, 'username':my_username, 'password':my_password}
response = requests.post(url, params=params, headers = headers)
print(response.status_code, response.reason)
我得到以下响应:
400 Bad Request
我还在参数中添加了 urllib.parse.urlencode,但仍然收到相同的响应错误
response = requests.post(url, params=urllib.parse.urlencode(params), headers = headers)
请求指导我做错了什么。 TIA
I am trying to make a simple request to get the access token from Citrix ShareFile, but it's throwing 400 error.
I am going exactly as it's mentioned in the documentation, except changing Python2 code with HTTPLib, with Python3 code with Requests. The code is:
url = 'https://{my_domain}.sharefile.com/oauth/token'
headers = {'Content_Type': 'application/x-www-form-urlencoded'}
params = {'grant_type':'password', 'client_id':my_client_id, 'client_secret':my_client_secret, 'username':my_username, 'password':my_password}
response = requests.post(url, params=params, headers = headers)
print(response.status_code, response.reason)
I get the following response:
400 Bad Request
I also added urllib.parse.urlencode to params, but am still getting the same response error
response = requests.post(url, params=urllib.parse.urlencode(params), headers = headers)
Request guidance on what am I doing wrong. TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它可能是密码,在 Sharefile 的上下文中,它意味着 app_password,而不是用于登录网站的密码。或者将response_type设置为“代码”。
SF Auth 是通过带有 GrandType 的 OAuth2: OAuth2 密码授予
这种方式对我有用:
响应包含令牌和刷新令牌。
It could be the password, in the context of Sharefile it means app_password and not the password used to login to website. Or response_type to 'code'.
SF Auth is through OAuth2 with a GrandType: OAuth2 Password Grant
This way works for me:
Response contains token and refresh token.
当我添加内容类型时,我的问题解决了。
检查并添加有效的内容类型
When I add content-type my issue solved.
Check and add valid content-type