[web2py] Re: unexpected end of stream - py4web

2020-03-02 Thread Edoardo Torrini
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///")
@action("produzione/")
def produzione(db, idmac, datafrom=None, datato=None):

object_list = []
sIstancePrd =  "mssql4://{}:{}@{}/{}".format("", "", 
"", 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

Il giorno giovedì 27 febbraio 2020 02:38:06 UTC+1, Dave S ha scritto:
>
>
>
> 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 ge

[web2py] Re: unexpected end of stream - py4web

2020-02-25 Thread Edoardo Torrini
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(return 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

Il giorno martedì 25 febbraio 2020 07:36:15 UTC+1, Dave S ha scritto:
>
>
>
> 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:
>>
>> [image: 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
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/066365ac-d359-4224-9a40-7642eacfcabf%40googlegroups.com.


[web2py] Re: unexpected end of stream - py4web

2020-02-23 Thread Edoardo Torrini
Hi,
I will attach you some part of code:

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




[image: 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:

[image: Controller - py4web.png] 
































this is the task of my app:

[image: task prd - py4web.png] 








































Thanks for your help.

Edoardo Torrini



Il giorno domenica 23 febbraio 2020 00:44:14 UTC+1, Massimo Di Pierro ha 
scritto:
>
> Can you show us some minimum code to rproduce?
>
> On Friday, 21 February 2020 20:38:08 UTC-8, Edoardo Torrini wrote:
>>
>> 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
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/6a55c277-f454-4cd5-b2ed-c11033fb9347%40googlegroups.com.


[web2py] unexpected end of stream - py4web

2020-02-21 Thread Edoardo Torrini
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

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/bdba800f-fa38-49a3-bc90-24d998df0c43%40googlegroups.com.


[web2py] py4web issue on get requests

2020-02-21 Thread Edoardo Torrini
Good morning,

I am a software developer and I want to create a project client-server.
The client is wrote in c# with xamarine and the server on py4web.
The client create request with some parameters and the server reply with a 
data in json form.
I use celery for scheduling the request and I create a task for each type 
of requests.

When with the client application I create a request [like the example 
below], the function await.response.Content.ReadAsStringAsync create an 
exception: *unexpected end of stream*

[image: Exception - Xamarine.png]


Server side the situation is that I create for each request a DAL and I 
define a table where I took the date to send to the client.
in this way:
[image: Controller - py4web.png]

I invoke  the task that reply the json file to the client in this way:

[image: task prd - py4web.png] 








































Someone know why the operation create this type of exception, I try using a 
request with chrome but the page was displayed correctly.
Thanks for the help.

Edoardo Torrini




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a25df1ac-50b3-4033-a661-374577da6281%40googlegroups.com.