gpt4 book ai didi

python - 401 客户端错误 : Unauthorized for url

转载 作者:行者123 更新时间:2023-12-03 09:42:52 27 4
gpt4 key购买 nike

最近我开始得到

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.soundcloud.com/oauth2/token



使用 soundcloud (0.5.0) Python 库。

它发生在
client = soundcloud.Client(client_id='id',
client_secret='secret',
username='user@mail.com',
password='passwd')

我仔细检查了我的凭据以确保它们不是原因。我试图从不同的 IP 和不同的机器获取客户端实例。在一天中的某些随机时间,我可以获得一个 Client 实例,但是一天中有 99.99% 的时间我都会收到错误消息。

该错误是否意味着我因某种原因被禁止?

最佳答案

这可能会有所帮助,我通过从配置文件中读取用户名和密码解决了类似的问题。
尝试:

# config.ini

[my_app]
CLIENT_ID = enter_your_id
CLIENT_SECRET = enter_your_secret
USERNAME = enter_username
PASSWORD = enter_password
安装 configparser来自 Python 2.6+ 的 Python 3.8: pip install configparser .
见大 documentation更多细节。
import configparser

config = configparser.RawConfigParser()
config.read('config.ini')


my_id = config.get('my_app', 'CLIENT_ID')
my_secret = config.get('my_app', 'CLIENT_SECRET')
my_user = config.get('my_app', 'USERNAME')
my_pass = config.get('my_app', 'PASSWORD')


client = soundcloud.Client(client_id=my_id,
client_secret=my_secret,
username=my_user,
password=my_pass)

关于python - 401 客户端错误 : Unauthorized for url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48497566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com