urbanairship / python-library

A Python library for using the Airship APIs for push notifications, reporting and other message types
https://docs.airship.com/api/libraries/python/
Other
82 stars 65 forks source link

Key error at urbanairship/common.py L 66 #41

Closed CatBia closed 5 years ago

CatBia commented 6 years ago

We only accept issues for bug reporting purposes.

All feature requests, implementation concerns or general queries should be sent to our support team.

Before completing the form below, please check the following:

Expected Behavior

When you upload a file to a Static List, and the csv is delimited with ; string:

import urbanairship as ua
from local_credentials import uas

airshipauth = ua.Airship(**uas)

#creating a Static List:
new_static_list = ua.devices.StaticList(airshipauth, 'new_static_list')
new_static_list.create()
# it returns {'ok':True}
#uploading list
with open('users.csv', 'rb') as _file:
    new_static_list.upload(_file)
# ????

Current Behavior

But, you get KeyError exception for some non-expected exception at core.py:

    new_static_list.upload(_file)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-46-d4f457512c8d> in <module>()
----> 1 result.upload(_file)

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/devices/static_lists.py in upload(self, csv_file)
     48             content_type='text/csv',
     49             version=3,
---> 50             encoding='gzip'
     51         )
     52         return response.json()

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/core.py in _request(self, method, body, url, content_type, version, params, encoding)
     63             raise common.Unauthorized
     64         elif not (200 <= response.status_code < 300):
---> 65             raise common.AirshipFailure.from_response(response)
     66 
     67         return response

~/anaconda3/envs/genericenv/lib/python3.6/site-packages/urbanairship/common.py in from_response(cls, response)
     63             error = payload['error']
     64             error_code = payload['error_code']
---> 65             details = payload['details']
     66         except (ValueError, TypeError):
     67             error = response.reason

KeyError: 'details'

Steps to Reproduce

Detailed Description

in Current Behaviour

pdxmele commented 6 years ago

Hi there, thanks for the report! However, the way we suggest you upload a list in our docs works fine for me. Can you not use that method for some reason? Doc is here, and example below: https://docs.urbanairship.com/reference/libraries/python/3.0.0/static_lists.html

Create list:

import urbanairship as ua
airship = ua.Airship(app_key, master_secret)
static_list = ua.devices.StaticList(airship, 'list_name')
static_list.description = 'description'
static_list.create()

RESPONSE: {u'ok': True}

Next, actually upload things into the list...

static_list = ua.devices.StaticList(airship, 'list_name')
csv_file = open('/path/to/list/list_name.csv', 'rb')
resp = static_list.upload(csv_file)
csv_file.close()
print resp

RESPONSE: {u'ok': True}

I also tried to reproduce what you did for this second part, but this works fine for me as well:

static_list = ua.devices.StaticList(airship, 'list_name')
with open('/path/to/list/list_name.csv', 'rb') as csv_file:
     resp = static_list.upload(csv_file)

print resp

RESPONSE: {u'ok': True}