Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

401 Client Error: Unauthorized for url

Recently I started to get

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

using soundcloud (0.5.0) Python library.

It happens in

client = soundcloud.Client(client_id='id',
                           client_secret='secret',
                           username='[email protected]',
                           password='passwd')

I double checked my credentials to make sure they are not the cause. I tried to get a Client instance from different IPs and different machines. At some random times during a day I can get a Client instance, but 99.99% of the day I get the error.

Does the error mean I was banned for some reason?

like image 769
Alex Avatar asked Jan 29 '18 09:01

Alex


1 Answers

It may be helpful, I solved a similar problem by reading the username and password from the configuration file.

Try:

# config.ini

[my_app]
CLIENT_ID     = enter_your_id
CLIENT_SECRET = enter_your_secret
USERNAME      = enter_username
PASSWORD      = enter_password

Install configparser from Python 3.8 for Python 2.6+: pip install configparser. See the great documentation for more details.

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)
like image 56
Milovan Tomašević Avatar answered Sep 22 '22 12:09

Milovan Tomašević