Weird issue with saving a simple product using the python sdk

Tourist
7 1 0

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()

0 Likes
Tourist
7 1 0

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

Shopify APIs & SDKs?

0 Likes
Highlighted
Community Manager
Community Manager
618 45 79

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,

0 Likes
Tourist
7 1 0

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

 

The workaround works though

0 Likes