carsonyl / pypac

Find and use proxy auto-config (PAC) files with Python and Requests.
https://pypac.readthedocs.io
Apache License 2.0
71 stars 19 forks source link

AttributeError: module 'js2py.translators' has no attribute 'pyjsparser' #2

Closed jfroy3 closed 7 years ago

jfroy3 commented 7 years ago

I installed pypac using pip on a fresh Python 3.6.0 install and I get the following error when trying to run the three lines sample:

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.`
>>> from pypac import PACSession
>>> session = PACSession()
>>> session.get('http://www.google.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\jfroy3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\jfroy3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypac\api.py", line 150, in request
    self.get_pac()
  File "C:\Users\jfroy3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypac\api.py", line 215, in get_pac
    pac = get_pac()
  File "C:\Users\jfroy3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypac\api.py", line 41, in get_pac
    return PACFile(downloaded_pac)
  File "C:\Users\jfroy3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypac\parser.py", line 20, in __init__
    orig_pyimport_meth = js2py.translators.pyjsparser.PyJsParser.parsePyimportStatement
AttributeError: module 'js2py.translators' has no attribute 'pyjsparser'

I'm not sure why and what the correct fix is, but I managed to patch it by removing 'pyjsparser.' from parser.py on lines 20, 21 and 33, like this:

20:        orig_pyimport_meth = js2py.translators.PyJsParser.parsePyimportStatement
21:        js2py.translators.PyJsParser.parsePyimportStatement = _raise_pyimport_error
...
33:            js2py.translators.PyJsParser.parsePyimportStatement = orig_pyimport_meth
carsonyl commented 7 years ago

Thanks for reporting this. I suspect the Js2Py library refactored the part I'm trying to patch. I'll take a look.

carsonyl commented 7 years ago

I've released https://pypi.python.org/pypi/pypac/0.2.1, which should solve this issue. Please let me know.

jfroy3 commented 7 years ago

I installed the latest and it did solve the issue. Thanks!