Repository: Shopify/shopify_python_api

Issue:
Shopify API url not working
Hi,

Currently, I'm just playing around, with this library. I created a development store and a private app.
When I'm trying to create a product I got the following error:

Python 3.7.2
ShopifyAPI==5.0.1

Traceback (most recent call last):
  File "C:\Users\danish\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 877, in _get_hostport
    port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: '16xxxxxxx9exxxx5xxxxxxxxxxxxc5@my-chandola.myshopify.com'

Any help will be appreciated.

Thanks 

Comments:

Patch:
diff --git a/README.md b/README.md
index 4959665..45111bc 100644
--- a/README.md
+++ b/README.md
@@ -85,15 +85,17 @@ service. pyactiveresource has to be configured with a fully authorized
 URL of a particular store first. To obtain that URL you can follow
 these steps:
 
-1.  First create a new application in either the partners admin or
-    your store admin. For a private App you'll need the API_KEY and
-    the PASSWORD otherwise you'll need the API_KEY and SHARED_SECRET.
+1.  First create a new application in either the partners admin or your store
+    admin. You will need an API_VERSION equal to a valid version string of a
+    [Shopify API Version](https://help.shopify.com/en/api/versioning). For a
+    private App you'll need the API_KEY and the PASSWORD otherwise you'll need
+    the API_KEY and SHARED_SECRET.
 
 2.  For a private App you just need to set the base site url as
     follows:
 
      ```python
-     shop_url = "https://%s:%s@SHOP_NAME.myshopify.com/admin" % (API_KEY, PASSWORD)
+     shop_url = "https://%s:%s@SHOP_NAME.myshopify.com/admin/api/%s" % (API_KEY, PASSWORD, API_VERSION)
      shopify.ShopifyResource.set_site(shop_url)
      ```
 
diff --git a/shopify/base.py b/shopify/base.py
index c902152..6cfee0e 100644
--- a/shopify/base.py
+++ b/shopify/base.py
@@ -77,6 +77,11 @@ class ShopifyResourceMeta(ResourceMeta):
         ShopifyResource._site = cls._threadlocal.site = value
         if value is not None:
             parts = urllib.parse.urlparse(value)
+            host = parts.hostname
+            if parts.port:
+                host += ":" + str(parts.port)
+            new_site = urllib.parse.urlunparse((parts.scheme, host, parts.path, '', '', ''))
+            ShopifyResource._site = cls._threadlocal.site = new_site
             if parts.username:
                 cls.user = urllib.parse.unquote(parts.username)
             if parts.password:


Test patch:
diff --git a/test/base_test.py b/test/base_test.py
index 9e78bdb..8847857 100644
--- a/test/base_test.py
+++ b/test/base_test.py
@@ -98,13 +98,18 @@ class BaseTest(TestCase):
         t2.start()
         t2.join()
 
-    def test_setting_site_without_token(self):
+    def test_setting_with_user_and_pass_strips_them(self):
+        shopify.ShopifyResource.clear_session()
         self.fake(
             'shop',
-            url='https://user:pass@this-is-my-test-show.myshopify.com/admin/api/unstable/shop.json',
+            url='https://this-is-my-test-show.myshopify.com/admin/shop.json',
             method='GET',
             body=self.load_fixture('shop'),
             headers={'Authorization': u'Basic dXNlcjpwYXNz'}
         )
-        shopify.ShopifyResource.set_site('https://user:pass@this-is-my-test-show.myshopify.com/admin/api/unstable')
+        API_KEY = 'user'
+        PASSWORD = 'pass'
+        shop_url = "https://%s:%s@this-is-my-test-show.myshopify.com/admin" % (API_KEY, PASSWORD)
+        shopify.ShopifyResource.set_site(shop_url)
         res = shopify.Shop.current()
+        self.assertEqual('Apple Computers', res.name)
diff --git a/test/session_test.py b/test/session_test.py
index d76c0f9..bf41591 100644
--- a/test/session_test.py
+++ b/test/session_test.py
@@ -84,7 +84,7 @@ class SessionTest(TestCase):
             assigned_site = shopify.ShopifyResource.site
 
         self.assertEqual('https://testshop.myshopify.com/admin/api/unstable', assigned_site)
-        self.assertEqual('https://None/admin/api/unstable', shopify.ShopifyResource.site)
+        self.assertEqual('https://none/admin/api/unstable', shopify.ShopifyResource.site)
 
     def test_create_permission_url_returns_correct_url_with_single_scope_and_redirect_uri(self):
         shopify.Session.setup(api_key="My_test_key", secret="My test secret")