unexpected end of stream - py4web

83 views
Skip to first unread message

Edoardo Torrini

unread,
Feb 21, 2020, 11:38:08 PM2/21/20
to web2py-users
Hi 

I create a project client/server compose by an application mobile (client) and a webservice (py4web).
the application create request to the webservice and the server reply.
I add a request scheduling using the celery and redis.
I follow pass for pass the guide on the official py4web site.

the problem is that when I generete the get request from the app create an exception: "unexpected end of stream"
Someone know how to fix this issue?

Thanks
Edoardo Torrini

Massimo Di Pierro

unread,
Feb 22, 2020, 6:44:14 PM2/22/20
to web2py-users
Can you show us some minimum code to rproduce?

Edoardo Torrini

unread,
Feb 24, 2020, 2:26:50 AM2/24/20
to web2py-users
Hi,
I will attach you some part of code:

The client is written in c# and is implemented in Xamarin:




Exception - Xamarine.png





























The server is written in python using the py4web framework, I have implemented the scheduling with celery/redis:
This is the controller of my app:

Controller - py4web.png

































this is the task of my app:

task prd - py4web.png









































Thanks for your help.

Edoardo Torrini

Dave S

unread,
Feb 25, 2020, 1:36:15 AM2/25/20
to web2py-users


On Sunday, February 23, 2020 at 11:26:50 PM UTC-8, Edoardo Torrini wrote:
Hi,
I will attach you some part of code:




this is the task of my app:

task prd - py4web.png









































I am still surprised by that last line.

Wouldn't the return exit produzione() while evaluating object_list and before actually calling the json.dumps() ?

/dps

Edoardo Torrini

unread,
Feb 25, 2020, 3:52:46 AM2/25/20
to web...@googlegroups.com
Hi Dave,
thanks for the reply, but I have notice that the code is wrong, I will explain.
Since I need three function in task I used another one to collector and after I redirect by an if statement.

So I have the funtion: my_task(func, filtri, *argv) and the function produzione(dbnow, filtri, *argv).
In the example I have synthesized the by putting only one function.

The correct one that I have test a lot of time is:

def produzione(dbnow, filtri, *argv):
    object_list
= []
   
   
if filtri == 0:
        rows
= dbnow(dbnow.Produzione.ID != None).select()
   
else:
        data1
= fixDate(argv[Filter.DataIn.value])
        data2
= fixDate(argv[Filter.DataFin.value])
        rows
= dbnow((dbnow.Produzione.OraInizio >= data1)&(dbnow.Produzione.OraInizio <= data2)&(dbnow.Produzione.Macchina == argv[Filter.IdMac.value])).select()


   
for record in rows:
        d
= collections.OrderedDict()
        d
['ID'] = record.ID
        d
['DataLoggerID'] = record.DataLoggerID
        d
['DataLoggerIDRiga'] = record.DataLoggerIDRiga
        d
['Utente'] = record.Utente if (record.Utente != None) else 0
        d
['Commessa'] = str(record.Commessa)
        d
['Lotto'] = str(record.Lotto)
        d
['Fase'] =  record.Fase if (record.Fase != None) else 0
        d
['Programma'] = str(record.Programma)
        d
['OraInizio'] = str(record.OraInizio)
        d
['OraProgrammazione'] = str(record.OraProgrammazione)
        d
['OraAttrezzaggio'] = str(record.OraAttrezzaggio)
        d
['OraPrimoPezzo'] = str(record.OraPrimoPezzo)
        d
['OraProduzione'] = str(record.OraProduzione)
        d
['OraFine'] = str(record.OraFine)
        d
['NPieghe'] = record.NPieghe if (record.NPieghe != None) else 0
        d
['Macchina'] = record.Macchina if (record.Macchina != None) else 0
        d
['PezziProdotti'] = record.PezziProdotti if (record.PezziProdotti != None) else 0
        object_list
.append(d)


   
return json.dumps(object_list)

Moreover if I run the request for a Browser and I can see the right result.

I hope I was clear in the explanation

Edoardo Torrini

Dave S

unread,
Feb 26, 2020, 8:38:06 PM2/26/20
to web2py-users


On Tuesday, February 25, 2020 at 12:52:46 AM UTC-8, Edoardo Torrini wrote:
Hi Dave,
thanks for the reply, but I have notice that the code is wrong, I will explain.
Since I need three function in task I used another one to collector and after I redirect by an if statement.

Okay, the correction takes care of my surprise, and I re-read your other thread with that in mind.

I am not sure why you are using a task; but that's a side issue.

Do I understand the results correctly?

* you have two versions, one with task and a test version without a task
* both versions run ok with browser-initiated requests
* the task version does not run ok from the client

Does the test version run ok from the client?

does the GetAsync() call generate an HTTP(S) request?  Have you looked at the request details in either log files or with Christian's suggestion of burp suite and compared that to the browser request?  How long does it take for the task to start and run?

Sorry I'm not more help, I've been "watching" py4web but haven't actually used it, and the same for celery, so I've not dived into the request details or more of scheduling than the celery tutorial.

Good luck!

Dave
/dps




Edoardo Torrini

unread,
Mar 2, 2020, 9:48:40 AM3/2/20
to web2py-users
Hi 

I have try to use burp proxy for know at what ip I generate the request: but using a proxy server on 127.0.0.1:8080 and redirect the traffic on the 192.168.x.x (my-ip):3111
Using google chrome, the result is correct and I see all my record in db.
Using the application it gave me an error: Failed to connect to /127.0.0.1:8080

I re-wrote the code and I taken out the task.

now the code is like this:

@action("produzione", method="GET")
@action("produzione/<db>/<idmac>/")
@action("produzione/<db>/<idmac>/<datafrom>/<datato>/")
def produzione(db, idmac, datafrom=None, datato=None):
   
    object_list
= []
    sIstancePrd
=  "mssql4://{}:{}@{}/{}".format("<my_user>", "<my_pass>", "<my_istance>", db)
    dbPrd
= DAL(sIstancePrd, folder=settings.DB_FOLDER, pool_size=settings.DB_POOL_SIZE, migrate_enabled=False)
   
    dbPrd
.define_table(
       
'Produzione',
       
Field('ID','id'),
       
Field('DataLoggerID', type='integer'),
       
Field('DataLoggerIDRiga', type='integer'),
       
Field('Utente', type='integer'),
       
Field('Commessa', type='string'),
       
Field('Lotto', type='string'),
       
Field('Fase', type='integer'),
       
Field('Programma', type='string'),
       
Field('OraInizio',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('OraProgrammazione',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('OraAttrezzaggio',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('OraPrimoPezzo',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('OraProduzione',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('OraFine',type='datetime',default=lambda r:datetime.datetime.now()),
       
Field('NPieghe', type='integer'),
       
Field('Macchina', type='integer'),
       
Field('PezziProdotti', type='integer'))
   
   
try:
       
if datafrom != None and datato != None:
            sSQL
= "SELECT * FROM Produzione WHERE OraInizio>='{}' AND OraFine<='{}' AND Macchina={}".format(datafrom, datato, idmac)
            rows
= dbPrd.executesql(sSQL)
       
else:
            rows
= dbPrd(dbPrd.Produzione.Macchina == idmac).select()

           
       
for record in rows:
            d
= collections.OrderedDict()
            d
['ID'] = record.ID
            d
['DataLoggerID'] = record.DataLoggerID
            d
['DataLoggerIDRiga'] = record.DataLoggerIDRiga
            d
['Utente'] = record.Utente if (record.Utente != None) else 0
            d
['Commessa'] = str(record.Commessa)
            d
['Lotto'] = str(record.Lotto)
            d
['Fase'] =  record.Fase if (record.Fase != None) else 0
            d
['Programma'] = str(record.Programma)
            d
['OraInizio'] = str(record.OraInizio)
            d
['OraProgrammazione'] = str(record.OraProgrammazione)
            d
['OraAttrezzaggio'] = str(record.OraAttrezzaggio)
            d
['OraPrimoPezzo'] = str(record.OraPrimoPezzo)
            d
['OraProduzione'] = str(record.OraProduzione)
            d
['OraFine'] = str(record.OraFine)
            d
['NPieghe'] = record.NPieghe if (record.NPieghe != None) else 0
            d
['Macchina'] = record.Macchina if (record.Macchina != None) else 0
            d
['PezziProdotti'] = record.PezziProdotti if (record.PezziProdotti != None) else 0
            object_list
.append(d)

           
   
except Exception as inst:
       
if settings.LOG_ENABLE:
           
with open(settings.LOG_PATH, "a+") as f:
                f
.write("Error Type: {}, Error: {}".format(type(inst), inst))
       
else:
           
print ("Error Type: {}, Error: {}".format(type(inst), inst))
   
   
return json.dumps(object_list)

but when I try to use getAsync() on the application it generate anyway the error: "Unexpected end of stream"
Normaly in the application I generate an http request.
someone know why or can help me for looking some forum or something else for resolve this issue.

Thanks

Edoardo Torrini
Reply all
Reply to author
Forward
0 new messages