JimCurryWang / python-shopee

pyshopee - Shopee Partner API Client for Python
https://pypi.org/project/pyshopee
MIT License
213 stars 82 forks source link

read time out #15

Open essramos opened 5 years ago

essramos commented 5 years ago

Hey Jim,

We are getting these errors, I know it might not relate to the library. But I am wondering if you are getting these as well?

Any idea why this is happening?

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/rq/worker.py", line 799, in perform_job
    rv = job.perform()
  File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 600, in perform
    self._result = self._execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 606, in _execute
    return self.func(*self.args, **self.kwargs)
  File "/app/agilascout_api/clock_helpers/shopee_logistics.py", line 70, in sync_logistics_shopee
    logistics = logistic.get_logistic_message(shop_id, partner_id, secret_key, ordersn=row.order_id)
  File "/app/agilascout_api/shopee_client/logistic.py", line 6, in get_logistic_message
    return client.logistic.get_logistic_message(**kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/pyshopee/logistic.py", line 46, in get_logistic_message
    return self.client.execute("logistics/tracking", "POST", kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/pyshopee/client.py", line 140, in execute
    resp = s.send(prepped, timeout=10)
  File "/app/.heroku/python/lib/python3.6/site-packages/raven/breadcrumbs.py", line 341, in send
    resp = real_send(self, request, *args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py", line 529, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='partner.shopeemobile.com', port=443): Read timed out. (read timeout=10)
JimCurryWang commented 5 years ago

Hi @essramos,

I think it might be a temporary internal server issue for the Shopee Open Platform.

Did you get this so often?

JimCurryWang commented 5 years ago

Maybe you can change the timeout params by yourself, however, I think 10 seconds is long enough for the API call.
(My Advice is waiting so patiently until the server become normal again)

# https://github.com/JimCurryWang/python-shopee/blob/master/pyshopee/client.py

 def execute(self, uri, method, body=None):
        ... 
        ... 
        s = Session()
        resp = s.send(prepped, timeout=10)
        resp = self._build_response(resp)
        return resp

And here are some requests exceptions explainations. https://github.com/kennethreitz/requests/blob/master/requests/exceptions.py

essramos commented 5 years ago

We manually increased the timeout to 15 and we are not seeing timeouts anymore, is there anyway to expose the timeout parameter?

JimCurryWang commented 5 years ago

Good Idea, maybe we can try it then.

JimCurryWang commented 5 years ago

@essramos,

I have made a PR in https://github.com/JimCurryWang/python-shopee/commit/bbada2fff71f53bfecef2f26f0f26e0bfe88aeaa .

Now we can add timeout params in each of your functions like below.

Maybe you can help me have a test or add this feature in the README document.

# demo
response = shopee.logistic.get_logistics(timeout=15)
print(response)
essramos commented 5 years ago

Thank you! Will try it out and let you know!