我正在尝试使用 OAuth2 通过 Python 获取 REST API 的授权令牌。我使用 CURL 成功做到了这一点,但使用 python 却失败了。我正在使用以下文档中提供的示例: https://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html
以下是我的代码:
#!/usr/bin/python
import requests
import requests_oauthlib
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient
client_id = 'AAAAAA'
client_secret = 'BBBBBB'
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)
print token
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) client_id value doesn't match HTTP Basic username value
Run Code Online (Sandbox Code Playgroud)
这是一个非常基本的 API,只需要 client_id 和 client_credentials 即可获取授权令牌。
所有信息将不胜感激。
如果我有一个文件,其中包含用空格分隔的不可预测元素,例如:
ABC123
ABC124
ABC125 ABC321 ABC222 ABC111 ABC333
ABC069 ABC450 ABC595
Run Code Online (Sandbox Code Playgroud)
如何将它们分别打印在单独的行中?(python 或 grep/awk 等)
我知道我可以读取文件(file.txt)然后使用每一行作为变量的一部分.
f = open( "file.txt", "r" )
for line in f:
sentence = "The line is: " + line
print (sentence)
f.close()
Run Code Online (Sandbox Code Playgroud)
但是,假设我有一个包含以下行的文件:
joe 123
mary 321
dave 432
Run Code Online (Sandbox Code Playgroud)
在bash我可以做类似的事情:
cat file.txt | while read name value
do
echo "The name is $name and the value is $value"
done
Run Code Online (Sandbox Code Playgroud)
我怎么能用Python做到这一点?换句话说,每行中的每个"单词"都将它们读作变量?
先感谢您!