Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Dev Space

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.
SOLVED

Python: Cannot import name 'Transport'

zacharypappas
7 - Meteor

Hello All,

I am working to pull data from an API using Python in Alteryx.  I have copied the JSONRPC package from python on my local computer to the site packages in Alteryx's location "C:\Program Files\Alteryx\bin\Miniconda3\Lib\site-packages".  When I try to execute the command "from jsonrpclib import jsonrpc" I get the following error "ImportError: cannot import name 'Transport' "

 

I am able to run the python script fully in the python application under the Miniconda3 subdirectory, so I am not sure why it will not work in Alteryx designer.

 

Screenshots below and I blocked off parts of the python code for company privacy.

 

Thank you,

Zachary Pappas

 

jsonrpcerror.PNGPythonJSONRPC.PNG

6 REPLIES 6
wthompson
Alteryx
Alteryx

Typically, the issue is you can not copy a package from one Python installation to another.

 

I would recommend doing a pip install of the package from the Miniconda3\Scripts subdirectory in Alteryx.

zacharypappas
7 - Meteor

Hey William,

I have removed/uninstalled the packages I copied into Alteryx Site Packages, and then installed them using the following command "Package.installPackages(['jsonrpc','jsonrpclib','impacket','jsonrpc_requests','jsonrpcclient','jsonschema','pprint'])"

 

When I ran "from jsonrpclib import jsonrpc", I received "No module named 'xmlrpclib'".  Xmlrpclibwould not install from packages, so I downloaded it from here (http://effbot.org/downloads/#xmlrpclib) and placed it into the site packages location.  When I ran it again, I still get the error "cannot import name 'Transport'

 

Thank you,

wthompson
Alteryx
Alteryx
In Python 3 xmlrpclib was renamed xmlrpc.client, so you need to fix the imports by changing xmlrpclib to xmlrpc.client.

from xmlrpc.client import Transport as XMLTransport
from xmlrpc.client import SafeTransport as XMLSafeTransport
from xmlrpc.client import ServerProxy as XMLServerProxy
from xmlrpc.client import _Method as XML_Method
zacharypappas
7 - Meteor

Slowly getting there.  I renamed xmlrpclib to xmlrpc.client, then got "No module named 'httplib'.  I had to change httplib to http.client.  I then got the error "Cannot import name 'HTTP'".  I saw the line that had "from httplib import HTTP, HTTPConnection" and I removed "HTTP," and it worked to run the original code "from jsonrpclib import jsonrpc".

 

 

Now I am trying to call the host using jsonrpc.ServerProxy("host:port") and I get "Attribute Error module 'urllib' has no attribute 'splittype'".  So far, I have tried changing urllib to urllib.request, urllib to urllib3.request, and urllib3, but it still gave me the same error.  I also tried to add import urllib.parse and change the splittype line to urllib.parse and no luck.

 

Thank you for the help!!

zacharypappas
7 - Meteor

And another update.  I used a web 2to3 python converter for the jsonrpc file, and added in the line "from urllib.parse import (splittype, splithost)" in the jsonrpc package.

Next, when calling the host, i changed it from "jsonrpc.serverproxy" to "jsonrpc.xmlserverproxy" and that worked. Now i am on the last line to call the API and I get "xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0".  I am only setting response equal to the report I am looking for with the proper parameters, so I am trying to figure this out!

zacharypappas
7 - Meteor

After a few issues with Alteryx saying jupyter notebook could not load, re-installs, and a final uninstall and reinstall, I was able to get python working again.  I received some tips from stack overflow here

that suggested I use jsonrpclib-pelix instead of jsonrpclib because it was supported on python 2, but not 3. Everything works now!