Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Python Fitbit dashboard 401 error, even when logged in browser

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: i7-5960X 4.4GHz, Noctua NH-D14, ASUS Rampage V, 32GB, RTX3080, 2TB NVMe SSD, 2x16TB HDD RAID0, Corsair HX1200, Thermaltake Overseer RX1, Samsung 4K curved 49" TV, 23" secondary

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

 

Dell XPS 2 in 1 2019, 32GB, 1TB, 4K

 

GPD Win 2

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 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 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 quote or @mention others, so they are notified of your reply

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

×