Weird issue with saving a simple product using the python sdk

steffenmande
Tourist
7 1 2

I got an issue following the basic steps for using the API with a private app.


Below is a piece of my code

 

    def __get_session_for_shop(self):
        shop_url = u'https://%s:%s@%s.myshopify.com/admin' % (self.config.api_key,
                                                              self.config.password,
                                                              self.config.store_name)
        shopify.ShopifyResource.set_site(shop_url)
        return shopify.Shop.current()

    # Create product
    def create_product(self, product):
        # If we got permission to create a product
        if self.__valid_request():
            print("We can create a product")
            if ('gtin' in product and shopify.Product.exists(product['gtin'])) or ('GTIN' in product and shopify.Product.exists(product['GTIN'])):
                pass
            else:
                shop = self.__get_session_for_shop()
                new_product = shopify.Product()
                new_product.title = "Name of the product"
                #new_product.handle = "The URL slug of the product"
                #new_product.product_type = "Category of the product"
                #new_product.body_html = "Description of the product"
                #new_product.vendor = "The Manufacturer of the product"
                #new_product.metafields_global_title_tag = "The meta title"
                #new_product.metafields_global_description_tag = "The description meta"
                #new_product.options = self.__get_options(product)
                #new_product.variants = self.__get_variants(product, new_product.options)
                saved_successfully = new_product.save()
                if not saved_successfully:
                    print("Failed at creating")

When i try to save the product i get an issue where it can't parse the port correctly on the url (that little documentation there is, says nothing about a port being specified?)

 

InvalidURL at /api/v1/products/

nonnumeric port: 'PASSWORD@vuuh-com.myshopify.com'

 

If i add a :80 to the shop url then i just get another error:

 

UnicodeError at /api/v1/products/

encoding with 'idna' codec failed (UnicodeError: label empty or too long)

 

What am i doing wrong ??

 

The error happens at new_product.save()

Replies 5 (5)
steffenmande
Tourist
7 1 2

Seems i cant remove this myself - can an admin move this to 

Shopify APIs & SDKs?

Busfox
Shopify Staff (Retired)
Shopify Staff (Retired)
628 49 110

Hi @steffenmande,

 

It sounds like you may be experiencing the issue highlighted in this issue. Can you give this a read over, especially the section at the bottom highlighting a workaround, and let me know if you continue to experience this issue?

 

Cheers,

Andrew | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

steffenmande
Tourist
7 1 2

Ended up working on a public app instead. So code is fully redone for that.

 

The workaround works though

AvidBrio
Shopify Expert
294 17 27

@steffenmande  i have same issue with Shopify app  please post your solution 

If you find our comment helpful, hit the like button and accept it as a solution.
Want us to implement custom changes in your store? Contact us
Email me directly - jim@avidbrio.com
Xardas
Shopify Partner
8 0 6

Hi @AvidBrio,

 

I'm not really sure about this but I've tried it with the id and it worked, just calling it for some reason made the save return true.

from the docs(https://github.com/Shopify/shopify_python_api😞

product = shopify.Product()
product.title = "Shopify Logo T-Shirt"
product.id                          # => 292082188312
product.save()                      # => True
shopify.Product.exists(product.id)  # => True
product = shopify.Product.find(292082188312)
# Resource holding our newly created Product object
# Inspect attributes with product.attributes
product.price = 19.99
product.save()                      # => True