xmlrpc python3 error

113 views
Skip to first unread message

Mark

unread,
Sep 26, 2019, 2:12:56 PM9/26/19
to web2py-users
Hello,

I got an error in python3.7, web2py 2.18.3.

Testing the following client side code in python2.7:
server = ServerProxy('https://127.0.0.1/myapp/query/call/xmlrpc', context=ssl._create_unverified_context())
server.test_xmlrpc()

If web2py run in python2.7, everything is fine.
If web2py run in python3.7, got error:
xmlrpclib.ProtocolError: <ProtocolError for 127.0.0.1/myapp/query/call/xmlrpc: 500 INTERNAL SERVER ERROR>

Thank you very much for your help.

Dave S

unread,
Sep 27, 2019, 2:00:42 AM9/27/19
to web2py-users

In .../applications/myapp/errors, is there a ticket for that?   Please post the stack trace, etc if you can.
Also, although I don't think it is the problem, let us know if you're using Rocket or some other front end to get to web2py.

/dps

Mark

unread,
Sep 27, 2019, 9:39:00 AM9/27/19
to web2py-users
I am using either Rocket or Azure, and get the same error.

Yes, there is a ticket, which I didn't realize before:

Traceback (most recent call last):
  File "R:\web2py\gluon\restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "R:\web2py\applications\myapp\models\db.py", line 321, in <module>
    'aaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  File "R:\web2py\gluon\tools.py", line 884, in __init__
    self.request_vars = request and request.vars or current.request.vars
  File "R:\web2py\gluon\globals.py", line 316, in vars
    self.parse_all_vars()
  File "R:\web2py\gluon\globals.py", line 287, in parse_all_vars
    for key, value in iteritems(self.post_vars):
  File "R:\web2py\gluon\globals.py", line 308, in post_vars
    self.parse_post_vars()
  File "R:\web2py\gluon\globals.py", line 244, in parse_post_vars
    dpost = cgi.FieldStorage(fp=body, environ=env, keep_blank_values=1)
  File "c:\python37\lib\cgi.py", line 491, in __init__
    self.read_single()
  File "c:\python37\lib\cgi.py", line 682, in read_single
    self.read_binary()
  File "c:\python37\lib\cgi.py", line 704, in read_binary
    self.file.write(data)
  File "c:\python37\lib\tempfile.py", line 481, in func_wrapper
    return func(*args, **kwargs)
TypeError: write() argument must be str, not bytes


Thanks!

Dave S

unread,
Oct 6, 2019, 5:29:31 PM10/6/19
to web2py-users
This looks like a place where something got missed in the Py3 work.  I suspect in cgi.py, maybe because testing used a uwsgi setup.  But I'm not ready to go into to it at this time.   Try filing a bug report at  <https://github.com/web2py>

Also, make sure we know what the front-end and middle-ware parts of the configuration are.

/dps

 

Mark

unread,
Oct 7, 2019, 5:08:12 PM10/7/19
to web2py-users
I submitted the bug report to the github. 

Thank you very much.

Lisandro

unread,
Mar 19, 2023, 6:56:20 PM3/19/23
to web2py-users
Hey there! 
I'm experiencing the same error after migrating to python3 and web2py version 2.23.1-stable+timestamp.2023.01.31.08.01.46
The traceback is the same, the error is originated when I try to access request.vars:

Traceback (most recent call last):
File "/home/limon/medios/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/limon/medios/applications/webmedios/controllers/ws.py", line 1423, in <module>
File "/home/limon/medios/gluon/globals.py", line 430, in <lambda>
self._caller = lambda f: f()
File "/home/limon/medios/applications/webmedios/controllers/ws.py", line 13, in call
if not request.vars.token or not db(db.sitios.token == request.vars.token).count():
File "/home/limon/medios/gluon/globals.py", line 325, in vars
self.parse_all_vars()
File "/home/limon/medios/gluon/globals.py", line 296, in parse_all_vars

for key, value in iteritems(self.post_vars):
File "/home/limon/medios/gluon/globals.py", line 317, in post_vars
self.parse_post_vars()
File "/home/limon/medios/gluon/globals.py", line 253, in parse_post_vars
dpost = cgi.FieldStorage(fp=body, environ=env, headers=headers, keep_blank_values=1)
File "/usr/lib64/python3.6/cgi.py", line 569, in __init__
self.read_single()
File "/usr/lib64/python3.6/cgi.py", line 761, in read_single
self.read_binary()
File "/usr/lib64/python3.6/cgi.py", line 783, in read_binary
self.file.write(data)
TypeError: write() argument must be str, not bytes

I've found that this was related to a python bug that is still opened, but at the same time I've seen that web2py received a workaround fix
I'm running the last web2py stable version. And just in case I checked the source code and it is running with the workaround fix. But the error still remains.
What should I try? I'm a bit lost :/

Lisandro

unread,
Mar 20, 2023, 8:41:18 AM3/20/23
to web2py-users
Just in case it helps someone, I was able to change my code to make it work. It's not a complete solution: I just started using args instead of vars.
I'll explain: in the client I was calling the service with some query string arguments, like this:

from gluon.contrib.simplejsonrpc import ServerProxy
ws = ServerProxy('http://mysite.com/ws/call/jsonrpc?token=ce3e1298-b7b3-40f6-83f2-f78c4360db8d')

... and in the function exposing the service I was using the token to identify the client:

from gluon.tools import Service
service = Service()

def call():
    if not db(db.clients.token == request.vars.token).count():
        raise HTTP(403)
    return service()


So I just had to make this change in the client:



... and this change in the service:

def call():
    if not db(db.clients.token == request.args(1)).count():
        raise HTTP(403)
    return service()

I hope it helps someone.
Best regards,
Lisandro
Reply all
Reply to author
Forward
0 new messages