09-27-2016 13:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-27-2016 13:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
I am developing a web app that analyzes user's fitbit data. I am using the gather_keys_oauth2.py program (found at https://github.com/orcasgit/python-fitbit) to get token to access a user's data.
The app works fine on my local machine. When gather_keys_oauth2.py is called, it opens a webpage to the fitbit authorization page, after entering a user login, the program collects the tokens, makes the API requests and completes the analysis. I've included the code snippet that does this at the bottom.
My problem is with running gather_keys_oauth2.py from the AWS server. When gather_keys_oauth2.py is called on the server, the webpage never opens (instead a quick page flashes by) and the connection times out.
Does anyone have an idea how to fix this problem? Is there some way to alter the code in gather_keys_aouth2.py so that a webpage will open on the user's machine? Here is the code snippet that works on my machine but not on the AWS server:
def browser_authorize(self):
"""
Open a browser to the authorization url and spool up a CherryPy
server to accept the response
"""
url, _ = self.oauth.authorize_token_url(redirect_uri=self.redirect_uri)
# Open the web browser in a new thread for command-line browser support
threading.Timer(1, webbrowser.open, args=(url,)).start()
cherrypy.quickstart(self)
10-03-2016 14:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



10-03-2016 14:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Have you filed an issue with the script's creator? That's usually the best way to get help with code Fitbit didn't create.
Since it works when run locally, my suspicion is that the script is not designed to be run remotely.
When running a Python application on your computer, Python can access the browser on your computer. When the Python script is run on an AWS virtual machine, the script is running on another computer, so it’s trying to open a browser window on that computer, which can’t be seen.
You might be able to modify the script to use the OAuth 2 Authorization Code Grant flow.

