juftin / lunchable

Python Client for the Lunch Money Developer API
https://juftin.com/lunchable/
MIT License
37 stars 8 forks source link

Error "Unexpected token" when attempting to create a transaction #104

Closed chachan closed 9 months ago

chachan commented 9 months ago

Description:

I'm getting {"name":"SyntaxError","message":"Unexpected token \'t\', \\"transactio\\"... is not valid JSON"} when trying to create a transaction, this is what I do:

211 B->             result = self.lunch_money.insert_transactions(
212                     transactions=transaction_insert,
213                     apply_rules=True,
214                     skip_duplicates=False,
215                     debit_as_negative=ScotiabankCreditCard._debit_as_negative(transaction),
216                     skip_balance_update=False,
217                 )
(Pdb) transaction_insert
TransactionInsertObject(date=datetime.date(2023, 11, 17), amount=9585.0, category_id=None, payee='', currency='crc', asset_id=12345, recurring_id=None, notes='some notes', status=None, external_id='some-id-123', tags=None)
(Pdb) ScotiabankCreditCard._debit_as_negative(transaction)
False

This is what happens:

319             response = self.request(
320                 method=method,
321                 url=url,
322                 params=json_safe_params,
323                 data=json_safe_payload,
324                 **kwargs,
325             )
326 B->         data = self.process_response(response=response)
327             return data
(Pdb) method
'POST'
(Pdb) url
'https://dev.lunchmoney.app/v1/transactions'
(Pdb) json_safe_params
(Pdb) json_safe_payload
{'transactions': [{'date': '2023-11-17', 'amount': 9585.0, 'payee': '', 'currency': 'crc', 'asset_id': 12345, 'notes': 'some notes', 'external_id': 'some-id-123'}], 'apply_rules': True, 'skip_duplicates': False, 'check_for_recurring': False, 'debit_as_negative': False, 'skip_balance_update': False}
(Pdb) pp kwargs
{}
(Pdb) n
Client error '400 Bad Request' for url 'https://dev.lunchmoney.app/v1/transactions'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
Traceback (most recent call last):
  File "/home/__/.cache/pypoetry/virtualenvs/lunchcr-UnUZhfHU-py3.10/lib/python3.10/site-packages/lunchable/models/_core.py", line 263, in process_response
    response.raise_for_status()
  File "/home/__/.cache/pypoetry/virtualenvs/lunchcr-UnUZhfHU-py3.10/lib/python3.10/site-packages/httpx/_models.py", line 758, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://dev.lunchmoney.app/v1/transactions'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
{"name":"SyntaxError","message":"Unexpected token 't', \"transactio\"... is not valid JSON"}
lunchable.exceptions.LunchMoneyHTTPError: {"name":"SyntaxError","message":"Unexpected token 't', \"transactio\"... is not valid JSON"}
> /home/__/.cache/pypoetry/virtualenvs/lunchcr-UnUZhfHU-py3.10/lib/python3.10/site-packages/lunchable/models/_core.py(326)make_request()
-> data = self.process_response(response=response)
(Pdb) response.content
b'{"name":"SyntaxError","message":"Unexpected token \'t\', \\"transactio\\"... is not valid JSON"}'
(Pdb) response.status_code
400
juftin commented 9 months ago

Shoot! I released a major change last night that must've broken this. I'll get this fixed up ASAP.

juftin commented 9 months ago

Hey @chachan the fix (https://github.com/juftin/lunchable/commit/588fc9c) was released on lunchable v1.0.1. I tested this myself, please let me know if you encounter any other issues and I will reopen this 🤝 Apologies for the problems!