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

Unable to import apicontrollers in python 3.5.2 #96

Closed
CRiva opened this issue Mar 20, 2018 · 7 comments
Closed

Unable to import apicontrollers in python 3.5.2 #96

CRiva opened this issue Mar 20, 2018 · 7 comments

Comments

@CRiva
Copy link

CRiva commented Mar 20, 2018

I am working on a project for my place of employment using the python sdk, and am receiving a massive error when trying to from authorizenet import apicontrollers.

In my module authorize_net_api.py I have made my own class to interface with the sdk.

it starts with:

import os, sys
import imp
from authorizenet import apicontractsv1
from authorizenet import apicontrollers
from authorizenet.utility import *
from authorizenet import utility

through the process of elimination I commented the lines out and tested one by one to see which line was giving the error, and sure enough, it was the apicontrollers

when running my own tests using tox, I'm not even testing the API yet, just importing my class, I get this

.tox/py3/lib/python3.5/site-packages/_pytest/config.py:329: in _getconftestmodules
    return self._path2confmods[path]
E   KeyError: local('<redacted>/tests/api')

During handling of the above exception, another exception occurred:
.tox/py3/lib/python3.5/site-packages/_pytest/config.py:360: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('<redacted>/tests/api/conftest.py')

During handling of the above exception, another exception occurred:
.tox/py3/lib/python3.5/site-packages/_pytest/config.py:366: in _importconftest
    mod = conftestpath.pyimport()
.tox/py3/lib/python3.5/site-packages/py/_path/local.py:668: in pyimport
    __import__(modname)
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:664: in _load_unlocked
    ???
<frozen importlib._bootstrap>:634: in _load_backward_compatible
    ???
.tox/py3/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:213: in load_module
    py.builtin.exec_(co, mod.__dict__)
tests/api/conftest.py:3: in <module>
    from botw.api.authorize_net_api import AuthorizeNetAPI
.tox/py3/lib/python3.5/site-packages/botw/api/authorize_net_api.py:4: in <module>
    from authorizenet import apicontrollers
.tox/py3/lib/python3.5/site-packages/authorizenet/apicontrollers.py:9: in <module>
    from authorizenet import apicontrollersbase
.tox/py3/lib/python3.5/site-packages/authorizenet/apicontrollersbase.py:11: in <module>
    from pip._vendor import requests
.tox/py3/lib/python3.5/site-packages/pip/__init__.py:45: in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
.tox/py3/lib/python3.5/site-packages/pip/vcs/mercurial.py:9: in <module>
    from pip.download import path_to_url
.tox/py3/lib/python3.5/site-packages/pip/download.py:40: in <module>
    from pip._vendor import requests, six
.tox/py3/lib/python3.5/site-packages/pip/_vendor/requests/__init__.py:98: in <module>
    from . import packages
.tox/py3/lib/python3.5/site-packages/pip/_vendor/requests/packages.py:12: in <module>
    sys.modules['pip._vendor.requests.packages.' + mod] = sys.modules["pip._vendor." + mod]
E   KeyError: 'pip._vendor.urllib3.contrib'

During handling of the above exception, another exception occurred:
.tox/py3/lib/python3.5/site-packages/py/_path/common.py:377: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
.tox/py3/lib/python3.5/site-packages/py/_path/common.py:418: in gen
    dirs = self.optsort([p for p in entries
.tox/py3/lib/python3.5/site-packages/py/_path/common.py:419: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
.tox/py3/lib/python3.5/site-packages/_pytest/main.py:411: in _recurse
    ihook = self.gethookproxy(path)
.tox/py3/lib/python3.5/site-packages/_pytest/main.py:315: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
.tox/py3/lib/python3.5/site-packages/_pytest/config.py:343: in _getconftestmodules
    mod = self._importconftest(conftestpath)
.tox/py3/lib/python3.5/site-packages/_pytest/config.py:368: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: KeyError('pip._vendor.urllib3.contrib',)
E     File "<frozen importlib._bootstrap>", line 969, in _find_and_load
E     File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
E     File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
E     File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 213, in load_module
E       py.builtin.exec_(co, mod.__dict__)
E     File "<redacted>/tests/api/conftest.py", line 3, in <module>
E       from botw.api.authorize_net_api import AuthorizeNetAPI
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/botw/api/authorize_net_api.py", line 4, in <module>
E       from authorizenet import apicontrollers
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/authorizenet/apicontrollers.py", line 9, in <module>
E       from authorizenet import apicontrollersbase
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/authorizenet/apicontrollersbase.py", line 11, in <module>
E       from pip._vendor import requests
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/pip/__init__.py", line 45, in <module>
E       from pip.vcs import git, mercurial, subversion, bazaar  # noqa
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/pip/vcs/mercurial.py", line 9, in <module>
E       from pip.download import path_to_url
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/pip/download.py", line 40, in <module>
E       from pip._vendor import requests, six
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/pip/_vendor/requests/__init__.py", line 98, in <module>
E       from . import packages
E     File "<redacted>/.tox/py3/lib/python3.5/site-packages/pip/_vendor/requests/packages.py", line 12, in <module>
E       sys.modules['pip._vendor.requests.packages.' + mod] = sys.modules["pip._vendor." + mod]

I was hoping you could advise and help.

Thank you.

@Sapbasu15
Copy link
Contributor

@CRiva , please take a look at the authorizenet sdk python sample code at https://github.com/AuthorizeNet/sample-code-python for help on how to use the python sdk. Try running the payment Transactions as given in the sample code.
There could be some problem in your class or the python environment packages which was used to interact with the sdk.

@CRiva
Copy link
Author

CRiva commented Mar 21, 2018

That's the thing, I'm not even interacting with the sdk yet.

Yes I've written my class, but I'm not even calling any of the methods within it yet, all I'm doing is importing the file.

To test, just to be sure, I copy/pasted the code from https://github.com/AuthorizeNet/sample-code-python/blob/master/TransactionReporting/get-settled-batch-list.py and attempted to just import the file.

and still it was the from authorizenet.apicontrollers import getSettledBatchListController that caused this same error.

@CRiva
Copy link
Author

CRiva commented Mar 21, 2018

I ran another small test.

It appears that the API works fine when I initiate from the same file, but when I try to import the file to use elsewhere, it errors out with the large error I put before.

@CRiva
Copy link
Author

CRiva commented Mar 21, 2018

Okay, I tried one more thing that I found here: pypa/pip#5079

Apparently the request library really messes some things up in the importing process.

Since I use the request package in this project as well, I was importing that before my authorize net class and it was erroring out.

By just reversing the import order, the error went away.

So this is probably not an issue with your code, but an issue with the python requests' code.

@Sapbasu15
Copy link
Contributor

@CRiva , seems like you are using the upgraded requests package. This would be similar to the issue #95 opened recently. We are looking into that issue and having explicit dependency on requests library.

@CRiva
Copy link
Author

CRiva commented Mar 22, 2018

@Sapbasu15 Thank you for pointing that out to me, and updating me on the situation. I will make sure I have my imports in the correct order for the time being until the problem is resolved.

@chsriniv9
Copy link

Fix is part of new sdk release 1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants