-
Notifications
You must be signed in to change notification settings - Fork 72
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
Refactored for Python3 compatibility #15
base: master
Are you sure you want to change the base?
Conversation
scrapy_jsonrpc/jsonrpc.py
Outdated
@@ -58,10 +58,11 @@ def jsonrpc_server_call(target, jsonrpc_request, json_decoder=None): | |||
json_decoder = ScrapyJSONDecoder() | |||
|
|||
try: | |||
req = json_decoder.decode(jsonrpc_request) | |||
req = json_decoder.decode(jsonrpc_request.decode()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.decode()
is almost always wrong - it decodes using sys.getdefaultencoding()
, which can vary across machines, and which is often ascii. I think it is better to decode from UTF-8 because this is what JSON standard requires.
bee6473
to
259162f
Compare
259162f
to
40d4ce3
Compare
I've also overridden the |
@kmike Any other observations on this PR? |
This works well for me with python3, no issues encountered |
Can we merge it? |
Hi @ChiraMircea can you guys write a test for this? It's extremely hard to reason on your code without tests. |
6fe00bd
to
13fe000
Compare
Hey @sibiryakov I added a few basic tests and py37 to tox, hope it's enough, please let me know if you think more tests are required. |
Refactored the code so that is Python3 compatible. It mostly had trouble when dealing with bytes and returning keys from dictionaries.
I also added
object
in the inheritance forJsonResource
andWebservice
because their base classes did not do, which required the call to the unbound__init__
method of the parent.This should solve, at least partially, issue #12 .