pushyrpc / pushy

Easy-as RPC. Zero-server RPC for Python and Java.
http://github.com/pushyrpc/pushy
45 stars 18 forks source link

Problem passing a dict to functions in remote interpreter #52

Closed norendren closed 10 years ago

norendren commented 10 years ago

Hi there,

I am using pushy to work with a MongoDB on a remote server and I'm running into a problem passing a dictionary to a function using the remote interpreter. I am using the pymongo library to remotely operate on the database and as you can see in the first part of the code below, calling the function with no arguments returns data successfully.

However, whenever I try to access information in the returned Mongo cursor, I get the error included in the code. If you're able to take a look at this, I would GREATLY appreciate it :)

import pushy import pymongo from pymongo import MongoClient

conn = pushy.connect("ssh:localhost", port=4444, username="USERNAME", password="PASSWORD")

client = conn.modules.pymongo.MongoClient()

db = client.hyperion

asset = db.asset

You can ignore the data output here, it is just to demonstrate that there IS output

asset.find_one() {u'asset_id': u'TEST_4NEWDL', u'status': u'error', u'run_type': u'DELETE', u'title': u'Pacific Rim Full Length', u'deleted': u'method': 2}, u'ca': u'movie': u'product_type': u'Subscription', r': u'TEST_4NEWDL01_98ec8b3b-cbf1-4a35-b55d-0a64c28aafaa', u'resource_id': u'TEST_4NEWDL01', u'resource_files': [{u'file_guid': u'1ccb95e3-4330-4396-8ad4-427ef0309ddf', u'filename': u'4AI0V01_720x480i30_1500kbps.ts'}, {u'file_guid': u'54cffc2f-aeca-4299-aa89-e63f4a928194', u'filename': u'4AI0V01_720x480i30_800kbps.ts'}], u'build_dir': u'/data/cvodhls/Bell/internal/working/TEST_4NEWDL01_98ec8b3b-cbf1-4a35-b55d-0a64c28aafaa/TEST_4NEWDL01_98ec8b3b-cbf1-4a35-b55d-0a64c28aafaa', u'resource_guid': u'98ec8b3b-cbf1-4a35-b55d-0a64c28aafaa', u'working_dir': u'/data/cvodhls/Bell/internal/working/TEST_4NEWDL01_98ec8b3b-cbf1-4a35-b55d-0a64c28aafaa', u'type': u'movie'}]}

asset.findone({'status':'error'}) Traceback (most recent call last): File "", line 1, in File "E:\Python26\lib\site-packages\pushy\protocol\proxy.py", line 255, in (conn.operator(type, self, args, kwargs)) File "E:\Python26\lib\site-packages\pushy\protocol\connection.py", line 66, in operator return self.sendrequest(type, (object, args, kwargs)) File "E:\Python26\lib\site-packages\pushy\protocol\baseconnection.py", line 329, in send_request return self.handle(m) File "E:\Python26\lib\site-packages\pushy\protocol\baseconnection.py", line 645, in handle raise e pushy.protocol.proxy.ExceptionProxy: 'status'

An example with the cursor

cursor = asset.find({'status':'error'})

cursor <pymongo.cursor.Cursor object at 0x1ccd190>

type(cursor) <class 'pushy.protocol.proxy.ObjectProxy'>

cursor.next() Traceback (most recent call last): File "", line 1, in File "E:\Python26\lib\site-packages\pushy\protocol\proxy.py", line 255, in (conn.operator(type_, self, args, kwargs)) File "E:\Python26\lib\site-packages\pushy\protocol\connection.py", line 66, in operator return self.sendrequest(type, (object, args, kwargs)) File "E:\Python26\lib\site-packages\pushy\protocol\baseconnection.py", line 329, in send_request return self.handle(m) File "E:\Python26\lib\site-packages\pushy\protocol\baseconnection.py", line 645, in handle raise e pushy.protocol.proxy.ExceptionProxy: 'status'

axw commented 10 years ago

@seeker44 When you call the function with a local dictionary the remote function is invoked with a proxy object, not a real dict. It looks like pymongo doesn't like that.

It's not ideal, but the following will work:

spec = conn.eval("{}")
spec.update({"status": "error"})
asset.find_one(spec)

(you can inline the dictionary keys/values in the eval if they're simple values)

norendren commented 10 years ago

You, sir, are a gentleman and a scholar. Pymongo must indeed dislike proxied dictionaries, but Pushy works entirely too well for what I'm doing to consider anything else.

Thank you SO much for the workaround!