Skip to content

When wrong API key used, "AttributeError: 'str' object has no attribute 'get'" (on string object: data) #35

@JamesParrott

Description

@JamesParrott

data is set here:
self._data = response.json()
but requests' Response.json() could "return a dictionary, list, etc. depending on what is in the response.":

https://requests.readthedocs.io/en/latest/api/#requests.Response.json

Traceback (most recent call last):

  File "C:\...\core.py", line 302, in _send_email_to_all_dependents
    response = pystmark.send_batch([pystmark.Message(**payload)
                                    for payload in payloads
                                   ],
                                   api_key=os.getenv('POSTMARK_API_KEY')
                                  )
  File "C:\...\Lib\site-packages\pystmark.py", line 138, in send_batch
    return _default_pyst_batch_sender.send(messages=messages, api_key=api_key,
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                           secure=secure, test=test,
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^
                                           **request_args)
                                           ^^^^^^^^^^^^^^^
  File "C:\...\Lib\site-packages\pystmark.py", line 1210, in send
    return super(BatchSender, self).send(message=messages, test=test,
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                         api_key=api_key, secure=secure,
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                         **request_args)
                                         ^^^^^^^^^^^^^^^
  File "C:\...\Lib\site-packages\pystmark.py", line 1124, in send
    return self._request(url, data=data, headers=headers, **request_args)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\Lib\site-packages\pystmark.py", line 1009, in _request
    return self.response_class(response, sender=self)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\Lib\site-packages\pystmark.py", line 820, in __init__
    self.messages = [MessageConfirmation(msg) for msg in data]
                     ~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\...\Lib\site-packages\pystmark.py", line 701, in __init__
    self.error_code = data.get('ErrorCode', 0)
                      ^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions