Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #31

Closed
arun21 opened this issue Jun 21, 2021 · 5 comments · Fixed by #32
Closed

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #31

arun21 opened this issue Jun 21, 2021 · 5 comments · Fixed by #32

Comments

@arun21
Copy link

arun21 commented Jun 21, 2021

Versions
Python version: Python 3.8.6
SDK version:
OS type: Linux
OS version: CentOS
OS architecture:

Describe the bug
I am using aftership-sdk-python library (aftership==1.0.post2) api create tracking api for posting orders to aftership since a month ago. I am using it as a batch process, processing around 10k records per day. since 2 days back, for few records I am getting this error below.. I tested my code, the argument I pass has no error but I get this error in the python module

Traceback (most recent call last):
    aftership.tracking.create_tracking(tracking=track_dict)
  File "/opt/root/lib64/python3.8/site-packages/aftership/tracking.py", line 10, in create_tracking
    return process_response(response)
  File "/opt/root/lib64/python3.8/site-packages/aftership/response.py", line 14, in process_response
    json_content = response.json()
  File "/opt/root/lib64/python3.8/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I get this error while using below code in loop

dict = {   "slug": carrier,
               "title": "",
               "emails": "",
               "customer_name": "",
                "order_id": order_id
           }

aftership.tracking.create_tracking(tracking=dict)

Could you please let me know how can I tackle this error, what happens sometimes is that even if I get this error, the record sometimes still gets posted to aftership, so if it tries to run second time I get BadRequest: Tracking already exists. as this outcome is related to another piece in my code, so I might need this error handled.

Please let me know if you need more details about this error.

Update:

If I add content-type in headers, will that solve my problem ? something like below: Please let me know

tracking = aftership.tracking.create_tracking(tracking=track_dict, headers={"Content-Type": "application/json"})

Thanks

@alviezhang
Copy link
Member

Hi @arun21, thank you for choosing AfterShip. The Python SDK seems to have received an unexpected response from the API server. Let me contact our back-end engineer and get back to you later.

@1415003719
Copy link

Hi @arun21, this error may be 5xx from the gateway layer. Because 5xx error is not in json format, so it causes JSONDecodeError. We have recently released a fix, the current 5xx error should be reduced a lot. If you still encounter JSONDecodeError, please re-request to solve it. We will continue to optimize to completely solve this problem.

@arun21
Copy link
Author

arun21 commented Jul 12, 2021

Hi @alviezhang @1415003719, Thanks for looking into it.

@1415003719: Can you tell me which version of aftership-sdk-python library is stable and I can use it with Python 3.8.6 and wont come across above error in library.

Thanks.

@alviezhang
Copy link
Member

alviezhang commented Jul 13, 2021

@arun21 I've release version 1.3.0 which treat json.JSONDecoder as aftership.exception.InternalError, and it also drops Python 3.5 support, but will not affect you.

@arun21
Copy link
Author

arun21 commented Jul 14, 2021

Thanks @alviezhang

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

Successfully merging a pull request may close this issue.

3 participants