Try ERPNext Buy Support Partners Foundation

Shopify HTTPSConnectionPool

Hi all,
I’ve use the Shopify Setting in ERP v11. When I make an order on Shopify, the customer is created, but not the product nor the Sales Order/Sales Invoice.
I added a print log in the Except here: https://github.com/frappe/erpnext/blob/develop/erpnext/erpnext_integrations/doctype/shopify_settings/sync_product.py#L10
Which returns this when I have 2 item in my cart:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/erpnext_integrations/doctype/shopify_settings/sync_product.py", line 18, in sync_item_from_shopify
    res = session.get(url, headers=get_header(shopify_settings))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //shop_url.smtshopify.com///admin/products/4446571167882.json (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc1d9a18fd0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

And if I only have 1 item, I get this error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/erpnext_integrations/doctype/shopify_settings/sync_product.py", line 18, in sync_item_from_shopify
    res = session.get(url, headers=get_header(shopify_settings))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //shop_url.smtshopify.com///admin/products/4449798914186.json (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc1d9a18fd0>: Failed to establish a new connection: [Errno -2] Name or service not known',))

And not that sure of what it meant…

I also receive 2 logs in shopify log:
1- erpnext.erpnext_integrations.connectors.shopify_connection.prepare_sales_invoice -> SUCCESS
2- the log above
I have 1 log in Error Log:
title: erpnext.erpnext_integrations.connectors.shopify_connection.sync_sales_order
error:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 103, in execute_job
    method(**kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/erpnext_integrations/connectors/shopify_connection.py", line 31, in sync_sales_order
    make_shopify_log(status="Error", message=e.message, exception=False)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/erpnext_integrations/doctype/shopify_log/shopify_log.py", line 29, in make_shopify_log
    log.save(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 260, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 310, in _save
    self.db_update()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 351, in db_update
    ), list(d.values()) + [name])
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 199, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 168, in execute
    query = self.mogrify(query, args)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 147, in mogrify
    query = query % self._escape_args(args, conn)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 122, in _escape_args
    return tuple(conn.literal(arg) for arg in args)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 122, in <genexpr>
    return tuple(conn.literal(arg) for arg in args)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 467, in literal
    return self.escape(obj, self.encoders)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 460, in escape
    return converters.escape_item(obj, self.charset, mapping=mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 27, in escape_item
    val = encoder(val, mapping)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 118, in escape_unicode
    return u"'%s'" % _escape_unicode(value)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/converters.py", line 73, in _escape_unicode
    return value.translate(_escape_table)
AttributeError: 'MaxRetryError' object has no attribute 'translate'

I don’t see any kind of connection limit on shopify side, so I really don’t know what could cause all those issue.
Any help would be appreciated!

as for the last error, the solution was to add this method: https://github.com/frappe/erpnext/blob/develop/erpnext/erpnext_integrations/doctype/shopify_log/shopify_log.py#L36 into my server (didn’t have it) and modify the method right above it with log.message = get_message(message)

1 Like

I think that this is a DNS problem, is the site new? Is the URL correct? Do you try to use Postman or something like that to try to get information from shopiffy?
The error is saying that after trying a lot of times, the server does not give a correct response. And it say that it is because the name cannot be resolved or is not known.

@Nahuel_Nso thanks for the reply,
no the site is not new and I think the url is fine?
I’m using the integrated API in ERPNext, and instead of doing the whole process from shopify, I’m doing these lines:

from erpnext.erpnext_integrations.doctype.shopify_settings.shopify_settings import get_shopify_url, get_header
from frappe.utils import cstr, cint, get_request_session
import requests
shopify_settings = frappe.get_doc("Shopify Settings")
url = get_shopify_url("admin/api/2019-04/products/{0}.json".format('444555888777999'), shopify_settings)
session = get_request_session()
try:
    print(url) #which prints: https://asd8hasd98ho8gfugy74:09irj8ur8349ifj9834rhi@https://shop_url.smtshopify.com//admin/api/2019-04/products/444555888777999.json
    res = session.get(url, headers=get_header(shopify_settings))
    print(res)
    res.raise_for_status()
    print("mid")
    shopify_item = res.json()["product"]
    make_item(shopify_settings.warehouse, shopify_item)
except requests.exceptions.ConnectionError as e: #Exception as e:
    print(e)

I try to ping the shop_url.smtshopify.com and it worked, so I think it’s not a DNS? I’m really not an expert on the matter :confused:

Do you tried enter the url in your browser? Or in postman? Does it work?

1 Like

you’re right, it isn’t. When I copy it in the browser, I get an URL like this:
https://https////shop_url.smtshopify.com//admin/api/2019-04/products/4449798914186.json
If I remove the second ‘https////’ and the second slash before ‘admin’ it works in the browser! Now when I try in the bench console, I get error concerning validation, which is alright! The connection seems to work now.
I will test some more just to be sure!

1 Like