Jump to content

Python Fitbit dashboard 401 error, even when logged in browser

432

Your python code isn't your browser, the site won't know you're "logged in" unless your code passes it an authentication cookie generated on a successful login. 

 

But you import the python fitbit module without using it, probably much easier to use the API that way with an API key for authentication. 

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Kilrah said:

Your python code isn't your browser, the site won't know you're "logged in" unless your code passes it an authentication cookie generated on a successful login. 

 

But you import the python fitbit module without using it, probably much easier to use the API that way with an API key for authentication. 

It returned a webpage saying my app made an invalid request.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Kilrah said:

Your python code isn't your browser, the site won't know you're "logged in" unless your code passes it an authentication cookie generated on a successful login. 

 

But you import the python fitbit module without using it, probably much easier to use the API that way with an API key for authentication. 

Did you look at my code and the error image?

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, 432 said:

It returned a webpage saying my app made an invalid request.

That's what a web API does, it returns some type of document (HTML, JSON, …). What type of document it returns depends on the request's Accept-header and whether the API supports that type. If you don't specify an Accept-header or they don't support that type, you'll get whatever is their default.

 

That doesn't mean being signed into their website on a browser magically caries over to your Python code. The browser is not going to share its authentication with your app (or rather, your app can't access the authentication token owned by your browser).

 

You'll first need to make an authentication request in your Python code, store the authentication token that comes back (most likely a cookie) and then include that in all future requests (as long as that authentication token is valid). Once the token expires you'll need to authenticate again. Without any type of authentication, I'd expect to get a HTTP status code 401 ("Unauthorized") for most of their API endpoints.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×