Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fitbit.exceptions.HTTPServerError when setting alarm. #124

Open
shaunakg opened this issue Oct 3, 2017 · 2 comments
Open

fitbit.exceptions.HTTPServerError when setting alarm. #124

shaunakg opened this issue Oct 3, 2017 · 2 comments

Comments

@shaunakg
Copy link

shaunakg commented Oct 3, 2017

I'm getting an exception from python with the following code:

# authorization code goes before this, etc. Note that fb = fitbit
reccurance = ['MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY','SUNDAY']
device_id = '123456789' # In the actual program this is a real device ID
fb.add_alarm(device_id, alarm_time, reccurance, recurring=False, enabled=True, label='Find Device Alarm', snooze_length=None, snooze_count=None, vibe='DEFAULT')

I've checked datetime formats and everything, but it still gives me the following output:

Traceback (most recent call last):
  File "PATH\TO\MY\PROGRAM\main.py", line 29, in <module>
    fb.add_alarm(device_id, alarm_time, reccurance, recurring=False, enabled=True, label='Find Device Alarm', snooze_length=None, snooze_count=None, vibe='DEFAULT')
  File "C:\Users\somebody\AppData\Local\Programs\Python\Python36-32\lib\site-packages\fitbit\api.py", line 716, in add_alarm
    return self.make_request(url, data=data, method="POST")
  File "C:\Users\somebody\AppData\Local\Programs\Python\Python36-32\lib\site-packages\fitbit\api.py", line 223, in make_request
    response = self.client.make_request(*args, **kwargs)
  File "C:\Users\somebody\AppData\Local\Programs\Python\Python36-32\lib\site-packages\fitbit\api.py", line 99, in make_request
    exceptions.detect_and_raise_error(response)
  File "C:\Users\somebody\AppData\Local\Programs\Python\Python36-32\lib\site-packages\fitbit\exceptions.py", line 94, in detect_and_raise_error
    raise HTTPServerError(response)
fitbit.exceptions.HTTPServerError: An error occurred with the Fitbit Web API while processing the request. Error id: A29E0282:7651_A92D91CB:01BB_59D3331F_4A63FA7:3D47

Any help with this? My program is just to set an alarm 20 seconds after the current time.

NB: Other commands like get_devices() and get_alarms() do work.

@LEXmono
Copy link

LEXmono commented Oct 21, 2017

You are not including the timezone in your request. Per the code, alarm_time should be a timezone aware datetime object.

You can do this with another module called pytz.

import pytz

tz = pytz.timezone("US/Eastern")
alarm_time = datetime.datetime(2017, 10, 21, 16, 0)
alarm_time = tz.localize(alarm_time, is_dst=None)

reccurance = ['MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY','SUNDAY']
device_id = '########' # In the actual program this is a real device ID
client.add_alarm(device_id, alarm_time, reccurance, recurring=False, enabled=True, label='Find Device Alarm', snooze_length=None, snooze_count=None, vibe='DEFAULT')

{'trackerAlarm': {'alarmId': ##########,
'deleted': False,
'enabled': True,
'label': 'Find Device Alarm',
'recurring': False,
'snoozeCount': 1,
'snoozeLength': 9,
'syncedToDevice': False,
'time': '16:00-04:00',
'vibe': 'DEFAULT',
'weekDays': []}}

@shaunakg
Copy link
Author

Thank you for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants