Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout exception yet uploaded the data #61

Closed
kadnan opened this issue Jan 17, 2021 · 6 comments
Closed

Timeout exception yet uploaded the data #61

kadnan opened this issue Jan 17, 2021 · 6 comments

Comments

@kadnan
Copy link

kadnan commented Jan 17, 2021

I am having a weird issue. I am using API for a Woocommerce setup on my local machine. Onr running I am getting the exceptions:

Traceback (most recent call last):
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/Users/Me/Data/anaconda3/lib/python3.7/http/client.py", line 1321, in getresponse
    response.begin()
  File "/Users/Me/Data/anaconda3/lib/python3.7/http/client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "/Users/Me/Data/anaconda3/lib/python3.7/http/client.py", line 257, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/Users/Me/Data/anaconda3/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py", line 368, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/packages/six.py", line 686, in reraise
    raise value
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 306, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='localhost', port=80): Read timed out. (read timeout=5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Me/Data/Business/NisaaPK/data_uploader_api/uploader.py", line 48, in <module>
    add_product(wcapi)
  File "/Users/Me/Data/Business/NisaaPK/data_uploader_api/uploader.py", line 31, in add_product
    print(wc.post("products", data))
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/woocommerce/api.py", line 112, in post
    return self.__request("POST", endpoint, data, **kwargs)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/woocommerce/api.py", line 103, in __request
    **kwargs
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/Users/Me/Data/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=80): Read timed out. (read timeout=5)

When I checked on the site the product was there! This is the code I am using:

from woocommerce import API


def add_product(wc):
    data = {
        "name": "Sample Product",
        "type": "simple",
        "regular_price": "1221.99",
        "sale_price": "921.99",
        "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",
        "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
        "categories": [
            {
                "id": 135
            },
        ],
        "tags": [

        ],
        "button_text": "Visit here to buy",
        "images": [
            {
                "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
            },
            {
                "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
            }
        ],
        "external_url": 'http://adnansiddiqi.me'
    }
    print(wc.post("products", data))


if __name__ == '__main__':
    KEY = 'XXX'
    SECRET = 'XXX'

    wcapi = API(
        url="http://localhost/shop.ab/",
        consumer_key=KEY,
        consumer_secret=SECRET,
        version="wc/v3"
    )

    # r = wcapi.get("products")
    # products = r.json()
    # print(len(products))
    add_product(wcapi)
@TinQ0
Copy link

TinQ0 commented Jan 27, 2021

I'm having the exact same problem and the product also get created. To be fair I don't really mind the errors as everything still seems to work perfectly fine, but how can you deal with it to still incorporate the product creation in a working program?

@kadnan
Copy link
Author

kadnan commented Jan 27, 2021

I'm having the exact same problem and the product also get created. To be fair I don't really mind the errors as everything still seems to work perfectly fine, but how can you deal with it to still incorporate the product creation in a working program?

Set the timeout around 20 seconds in the API() constructor and it should work for you then.

@TinQ0
Copy link

TinQ0 commented Jan 27, 2021

Had to set it to 30 for it too work. Our site is indeed quite slow so that might be the culprit. Thank you!

@claudiosanches
Copy link
Contributor

Hello, thanks for reporting it.

This one is an issue with requests library, you can issue more details in psf/requests#5291
My advice besides changing timeout it's to implement a try/catch to handle those errors.

I'm closing for now since it's an issue from requests and there's some workarounds for it.

@tazasahar
Copy link

@claudiosanches I am getting this error as well. I have tried increasing the timeout to 30, 50, and even 100 but it doesn't
seem to work. Is there any work around?

@singcang
Copy link

me too :(

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

No branches or pull requests

5 participants