joshmarshall / jsonrpclib

A Python JSON-RPC over HTTP that mirrors xmlrpclib syntax.
Other
447 stars 144 forks source link

Using this library with Python 3.x #58

Open SajidSalim opened 7 years ago

SajidSalim commented 7 years ago

Can this library be supported to work for Python 3.x if certain issues are fixed? The following are the basic issues I have found. There are no compilation issues.

jsonrpc.py: from xmlrpclib becomes from xmlrpc.client. from httplib import HTTP, HTTPConnection becomes from http.client import HTTPConnection

SimpleJSONRPCServer.py: SimpleXMLRPCServer becomes xmlrpc.server ServerSocket becomes serversocket Line 62: except Exception, e: becomes except Exception as e:

Any other changes I am missing?

bkda commented 7 years ago

The xmlrpclib module has been renamed to xmlrpc.client in Python 3.

See Python2 xmlrpclib

This project has not been updated for two years, so you can find this file

jsonrpc.py and change

from xmlrpclib import Transport as XMLTransport
from xmlrpclib import SafeTransport as XMLSafeTransport
from xmlrpclib import ServerProxy as XMLServerProxy
from xmlrpclib import _Method as XML_Method

to

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 
prs247au commented 7 years ago

I am after the same thing. I've got it working in Python 3.5.2 (win10) with all tests passing, but have broken it for 2.7 (linux) which I'm looking into now. There's a bit more to the changes than those listed above.

tony-bony commented 3 years ago

You can use 2to3 to convert the source file:

2to3 -w jsonrpc.py

This will do the above for you. Then change manually these two lines:

line 168 from http.client import HTTP, HTTPConnection
line 186     class UnixHTTP(HTTP):

To

line 168 from http.client import HTTPConnection
line 186     class UnixHTTP(HTTPConnection):

The best option is however to switch to jsonrpclib-pelix which supports Python3

joshmarshall commented 3 years ago

@SajidSalim / @tony-bony / @prs247au I know it is several years since you posted, but this should be resolved in 0.2.1 on PyPI for Python 3.5+. Please let me know if there are other issues (assuming you are still using something like this library), otherwise I will close the issue.