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

Getting TypeError when trying to Webhook.find() #150

Closed
funkybob opened this issue Jul 27, 2016 · 9 comments
Closed

Getting TypeError when trying to Webhook.find() #150

funkybob opened this issue Jul 27, 2016 · 9 comments

Comments

@funkybob
Copy link

Just updated to latest everything:
py3.5
ShopifyAPI (2.1.5)
pyactiveresource (2.1.2)

And the following code:

    if not shopify.Webhook.find(topic='orders/paid'):

Raise the following exception:

  File ".../venv/lib/python3.5/site-packages/pyactiveresource/activeresource.py", line 720, in _prefix_parameters
    for match in template.pattern.finditer(path):
TypeError: cannot use a string pattern on a bytes-like object

Some basic print debug shows the value of path at that point is b''.

If I modify the offending code to use path.encode('utf-8') it succeeds, but fails later at:

  File ".../venv/lib/python3.5/site-packages/pyactiveresource/activeresource.py", line 737, in _prefix
    path = re.sub('/$', '', cls.prefix_source)
  File ".../venv/lib/python3.5/re.py", line 182, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: cannot use a string pattern on a bytes-like object

So either this is byte/string failure in pyactiveresource, or ShopifyAPI isn't setting values on its Webhook resource that the other lib needs.

@jamiemtdwyer jamiemtdwyer self-assigned this Jul 27, 2016
@flux627
Copy link
Contributor

flux627 commented Aug 11, 2016

Haven't looked into this yet, however I do want to say that 2.1.5 is not the latest release. There was a 2.1.6 release within the last month, however it is not updated on PyPI- you will need to install it using the GitHub address:

within requirements.txt
-e git+git@github.com:Shopify/shopify_python_api.git@e3e6591#egg=2.1.6

using pip
pip install git+git@github.com:Shopify/shopify_python_api.git@e3e6591

@funkybob
Copy link
Author

A better option for requirements.txt is

git+https://github.com/Shopify/shopify_python_api.git@v2.1.6

There's no need for the -e switch, and better to target the tag than a meaningless rev.

@flux627
Copy link
Contributor

flux627 commented Aug 12, 2016

Thanks funkybob for the correction, I'll update my own procedures with this as well

@EvanDarwin
Copy link

I am also experiencing this issue on 2.1.8.

Simply doing:

products = shopify.Product.get()

Results in:

  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 613, in _collection_path
    'prefix': cls._prefix(prefix_options),
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 737, in _prefix
    path = re.sub('/$', '', cls.prefix_source)
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: can't use a string pattern on a bytes-like object

@flux627
Copy link
Contributor

flux627 commented Oct 28, 2016

get() should not be called directly from Product. Did you mean find()?

@EvanDarwin
Copy link

EvanDarwin commented Oct 28, 2016

@flux627, My fault. I'm still getting the exact same error though.

Even when assigning shopify.Product.find() to a variable (not shown here), I still get this TypeError.

Traceback (most recent call last):
  File "test_shopify.py", line 15, in <module>
    print(shopify.Product.find())
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 385, in find
    return cls._find_every(from_=from_, **kwargs)
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 522, in _find_every
    path = cls._collection_path(prefix_options, query_options)
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 613, in _collection_path
    'prefix': cls._prefix(prefix_options),
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/site-packages/pyactiveresource/activeresource.py", line 737, in _prefix
    path = re.sub('/$', '', cls.prefix_source)
  File "/home/ubuntu/.virtualenvs/crm/lib/python3.4/re.py", line 179, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: can't use a string pattern on a bytes-like object

@flux627
Copy link
Contributor

flux627 commented Nov 1, 2016

I think it's possible that this module does not support Python 3.4. Try it in 2.7 and see if you still get the same error.

@travis-st
Copy link

travis-st commented Sep 7, 2017

I had this issue when I did not activate the session prior to making the .find() call

shopify.ShopifyResource.activate_session(session)

@jamiemtdwyer jamiemtdwyer removed their assignment Sep 28, 2018
@jamiemtdwyer
Copy link
Contributor

I'm not able to replicate this in Python 2.7.9 or 3.5.1. As suggested by the other commenter, make sure your session is initialized first.

If anyone is able to replicate this, please feel free to re-open it.

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