Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Access error to authorization uri to get authorization code

Access error to authorization uri to get authorization code

Plan

Premium

Country

Japan

 

Device

Windows11 PC

Operating System

Windows 11

 

My Question or Issue

 

-I have tried to get my liked tracks list as json  with coding python/spotipy according to api reference below.I have used Jupyter Lab as editor.

https://developer.spotify.com/documentation/web-api/reference/get-users-saved-tracks

On the way to do that, I knew it needs authorization code .

So, my code and the result returned is below.

I clicked authorization url, it was redirected to my spotify site once.

Then I pressed "Agree" . but next  it has shown 404   not found error below.

 

Jupyter Server 404 : Not Found You are requesting a page that does not exist!

 

I have set redirect URI as follows.

http://localhost:8889/callback

redirect URIs are all the same in my code and settings in Spotify developer dashboard.

 

The reason why I am using 8889 is my port on my Jupyter lab (web server port) is 

http://localhost:8889

Although I have not been  sure if I should make redirect URI same as port my Jupter Lab Server. ..

Should it be same?

The more one reason, port # 8888 was already used in my PC by other web server.

 

 

I made it all the same regarding on 3 redirect URIs.

 

Could anyone please give me some advice

on what is causing this error and how to fix it?
I am waiting for your instructions if there is anything I should try to solve it. 

 

 

 

 

 

https://developer.spotify.com/documentation/web-api/tutorials/code-flow

 

A part of My code

 

# Set up the SpotifyOAuth object
auth_manager = SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
scope=scope
)

# Get the authorization URL and have the user authorize your app
auth_url = auth_manager.get_authorize_url()
print(f'Please visit this URL to authorize the application: {auth_url}')

# After the user authorizes your app, get the authorization code from the redirect URL
# and use it to get an access token
code = input('Please enter the authorization code: ')
auth_manager.get_access_token(code)

# Now you can use Spotipy to make authenticated API requests
sp = spotipy.Spotify(auth_manager=auth_manager)
results = sp.current_user_saved_tracks(limit=10, offset=5, market='JP')
print(results)

 

The result returned

 

Please visit this URL to authorize the application: https://accounts.spotify.com/authorize?client_id=xxxxxxxxxxxxxxxxxxx&response_type=code&redirect_uri...

Please enter the authorization code:

 

 

 

 

 

 

 

 

 

mycode.jpg
result_returned.jpg
Reply
4 Replies

The following answer is for Google Colab, but it should also work for you: https://stackoverflow.com/a/68651136/7111585

XimzendRising Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

1.jpg2.jpg1.jpg2.jpgThanks. I tried that way like below.

 

# Set up the SpotifyOAuth object
auth_manager = SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
scope=scope,
open_browser = False
)

 

But the same incident has still happened.

So Next,

I changed redirect URI in several cases and tried that some times.

http://localhost:8080/callback

The port 8080 above has not been used by Jupyter lab. 

http://localhost:9009/callback.

The port 9090 has shown "established" on the powershell by  command prompt "netstat -na".

The redirect URI in my code and the redirect URI in the settings in Spotify developer dashboard are same.

 

Next, I tried to execute same code in VScode that does not use web server.

The result has shown the message and promt.

 

>>

Please visit this URL to authorize the application: https://accounts.spotify.com/authorize?client_id=XXXXXXXXXXXXXX&response_type=code&redirect_uri=http...
Please enter the authorization code:

So I clicked URL has been shown.

However, The same 404 error like below  has still happened.

Is there anyone who knows what the cause is?
I would appreciate it if you could give me some hints to find a solution.

 

 

 

>>>

 

This site cannot be reached Connection refused on localhost.
try next

Check connection
Check proxies and firewalls
ERR_CONNECTION_REFUSED
Check your internet connection
Check your cables and restart any network devices you are using (routers, modems, etc.).
Allow Chrome access to your network in your firewall and antivirus settings.
If it already appears as a program allowed to access the network, try removing it from the list and adding it again.

 

If you are using a proxy server...
Check your proxy settings or contact your network administrator to see if your proxy server is working properly. If you are not using a proxy server, please try the next method. To disable this option: Go to Chrome menu > Settings > Show advanced settings… > Change proxy settings… > LAN settings and uncheck Use a proxy server for your LAN to

 

 

 

 

 

 

 

 

If I understand you correctly, you aren't able to input any text after the printed : .

Can you try to use: https://github.com/spotipy-dev/spotipy#with-user-authentication

XimzendRising Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Thank you for your information.
I already checked the Github link you gave me.
but
After doing some research on my own,
Turns out the Redirect URI itself wasn't the real cause of my problem.
What I needed to solve the problem was the work described on the following site. (get access token using linux command)
The site below is written in Japanese, but this information is valuable for those who have the same problem as me.
https://takagi.blog/get-and-refresh-access-tokens-for-the-spotify-web-api/
Therefore, we recommend using machine translation to check the information on the site.
The work is still in progress.

Suggested posts