Error on running script
thundercatsNZ opened this issue · 5 comments
Hi, I get the following error when executing:
Traceback (most recent call last):
File "/Users/paul/Software/GitHub/fitbit-googlefit/remote.py", line 122, in CreateGoogleFitDataSource
dataSourceId=self.convertor.GetDataSourceId(dataType)).execute()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.step_count.delta%3Afitbit%3Acharge-hr%3Aio.pkp.fbit-gfit?alt=json returned "DataSourceId not found: raw:com.google.step_count.delta:fitbit:charge-hr:io.pkp.fbit-gfit">
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "app.py", line 110, in <module>
main()
File "app.py", line 60, in main
remote.CreateGoogleFitDataSource(dataType)
File "/Users/paul/Software/GitHub/fitbit-googlefit/remote.py", line 129, in CreateGoogleFitDataSource
body=self.convertor.GetDataSource(dataType)).execute()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 409 when requesting https://www.googleapis.com/fitness/v1/users/me/dataSources?alt=json returned "Data Source: raw:com.google.step_count.delta:453688148430:fitbit:charge-hr:io.pkp.fbit-gfit already exists">
Any idea what I have configured incorrectly?
Thanks!
Paul
The problem is with the IDs that the project generates. Google requires that they are formatted like:
type:dataType.name:developer-project-number:device.manufacturer:device.model:device.uid:dataStreamName
reference
but the code doesn't include the project number.
You can get your project number in the Google Developers Console in a spot like:
https://console.developers.google.com/iam-admin/settings?project=
Assuming your project id was: 123456789012
, you can fix the code by modifying the end of converters.py
Change it from:
return ':'.join((
dataSource['type'],
dataSource['dataType']['name'],
dataSource['device']['manufacturer'],
dataSource['device']['model'],
dataSource['device']['uid']))
to
return ':'.join((
dataSource['type'],
dataSource['dataType']['name'],
'123456789012',
dataSource['device']['manufacturer'],
dataSource['device']['model'],
dataSource['device']['uid']))
The commit you referenced is cleaner than my way, and doesn't require user interaction to modify the config.
When I ran the code in master branch, it generated:
raw:com.google.step_count.delta:<obfuscated-projec-number>:fitbit:charge-hr:<obfuscated-uid>
I could see them by going to:
https://developers.google.com/apis-explorer/#search/fitness.users.datasources.list/m/fitness/v1/fitness.users.dataSources.list?userId=me
I'm not sure how it got created to cause the error on the first run of the code, but for all later runs, it failed because the DataSourceId generated wasn't correct, so it can't find it, and it tries to create it again.
I have the same problem, 403... :/
I believe this issue should be resolved by the recent changes in the repo. Please reopen if not.