Python Citrix Sharefile 令牌请求给出 400 错误

发布于 2025-01-15 04:42:44 字数 787 浏览 5 评论 0原文

我正在尝试发出一个简单的请求以从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悟红尘 2025-01-22 04:42:44

它可能是密码,在 Sharefile 的上下文中,它意味着 app_password,而不是用于登录网站的密码。或者将response_type设置为“代码”。

SF Auth 是通过带有 GrandType 的 OAuth2: OAuth2 密码授予

这种方式对我有用:

url = 'https://{my_domain}.sharefile.com/oauth/token'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
    'response_type': 'code',
    'grant_type': 'password',
    'client_id': '<YOUR CLIENT ID>',
    'client_secret': '<YOUR SECRET>',
    'username': '<USERNAME>',
    'password': '<APP_PASSWORD>'  # not regular password to login using web
}
response = requests.post(url, data=data, headers=headers)

响应包含令牌和刷新令牌。

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:

url = 'https://{my_domain}.sharefile.com/oauth/token'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
    'response_type': 'code',
    'grant_type': 'password',
    'client_id': '<YOUR CLIENT ID>',
    'client_secret': '<YOUR SECRET>',
    'username': '<USERNAME>',
    'password': '<APP_PASSWORD>'  # not regular password to login using web
}
response = requests.post(url, data=data, headers=headers)

Response contains token and refresh token.

九歌凝 2025-01-22 04:42:44

当我添加内容类型时,我的问题解决了。

检查并添加有效的内容类型

When I add content-type my issue solved.

Check and add valid content-type

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文