request vars data file

23 views
Skip to first unread message

黄祥

unread,
Feb 18, 2022, 5:04:19 PM2/18/22
to web2py-users

def barcode():
    req_vars = request.vars
    #first_key = list(req_vars.keys() )[0]
    first_key = next(iter(req_vars) )
    reader = BarCodeReader()
    results = reader.decode(first_key)
    return results

"""
curl -X POST --user admin:password -d '@filename.png' -i http://localhost:8000/test/scan/barcode.json

curl -X POST --user admin:password --data-binary '@filename.png' -i http://localhost:8000/test/scan/barcode.json
"""

error traceback

Traceback (most recent call last):
  File "/Users/sugizo/Downloads/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/Users/sugizo/Downloads/web2py/applications/test/controllers/scan.py", line 26, in <module>
  File "/Users/sugizo/Downloads/web2py/gluon/globals.py", line 430, in <lambda>
    self._caller = lambda f: f()
  File "/Users/sugizo/Downloads/web2py/applications/test/controllers/scan.py", line 15, in barcode
    results = reader.decode(first_key)
  File "/Users/sugizo/opt/miniconda3/envs/python3_test/lib/python3.7/site-packages/pyzxing/reader.py", line 51, in decode
    raise FileNotFoundError
FileNotFoundError

but when check for first_key (in function above just return first_key)
the result is
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
X-Powered-By: web2py
Content-Type: application/json
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Fri, 18 Feb 2022 21:50:35 GMT
Pragma: no-cache
Date: Fri, 18 Feb 2022 21:50:35 GMT
Server: Rocket 1.2.6 Python/3.7.11
Content-Length: 417
Connection: keep-alive

L@pk��N"��w��Ƙ9m�ϓ�6�*"��������gA�!F��o،�ۅ�p�
                   �5�q�/���f�  v��Ɗ��?j'%��q�
                                              ��o�Gņ��ږs0���.�2v���O11G0i�k���.[z��b)�;L���Q���c_

so i assume, the first_key is passed by request.vars as a binary
but when trying to execute it on terminal (create another file then execute : python test0.py it work e.g. results = reader.decode(filename.png)

objective
user send data file via curl, and web2py process the file and return it content text

question
any idea how to achieve it using web2py way ?

thanks and best regards,
stifan
Reply all
Reply to author
Forward
0 new messages