How can I maintain a constant data send to a URL in Python?

0

Good afternoon friends, I am somewhat desperate with an error I get when sending data captured by an arduino, which sent them through the COM port to a Raspberry and within this I execute the code in python to capture the data (these data are concatenated), separate them, assign them a name and then send them via URL to a target IP to process the information.

This is the code that I execute

#!/usr/bin/python

# Importamos la libreira de PySerial

import requests
import serial
import time


ser=serial.Serial('/dev/ttyACM0',9600)
Sensor1 = "1"
Sensor2 = "2"
Sensor3 = "3"
Sensor4 = "4"
while 1:

    string = str(ser.readline().decode().strip('\r\n'))
    produccion,vivienda = string.split('*')

    url="http://10.100.64.54/insert/"+Sensor1+"/"+produccion   
    url2="http://10.100.64.54/insert/"+Sensor2+"/"+vivienda 

    response=request.get(url) # response 200 = envio satisfactorio
    print(response)  
    response2=request.get(url2) # response 200 = envio satisfactorio
    print(response2)

at the moment of executing it, it keeps a stable time, it sends me the data that I get, I can process it and everything, but it starts to give me a response 500 that I think means that the data was not obtained.

When this OK gives me the following:

response(2oo)
response(2oo)
response(2oo)
response(2oo)
response(2oo)
response(2oo)
response(5oo) <--- noe por que me arroja ese valor :( tampoco se que es, si 
                        pueden ayudarme.
response(2oo) 
response(2oo)
response(2oo)
response(2oo)

but after a moment he gives me the following error:

  

Traceback (most recent call last):   File "/home/pi/Desktop/newlas.py", line 23, in   response = requests.get (url) # response 200 = successful sending.   File "/usr/lib/python3/dist-packages/requests/api.py", line 70, in get   return request ('get', url, params = params, ** kwargs)   File "/usr/lib/python3/dist-packages/requests/api.py", line 56, in request   return session.request (method = method, url = url, ** kwargs)   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 488, in > request   resp = self.send (prep, ** send_kwargs)   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 609, in send   r = adapter.send (request, ** kwargs)   File "/usr/lib/python3/dist-packages/requests/adapters.py", line 473, in send   raise ConnectionError (err, request = request)   requests.exceptions.ConnectionError: ('Connection aborted.',> ConnectionResetError (104, 'Connection reset by peer'))

     

help friends, I can not occupy a try catch either, as you can see in the code, I just met python. and it's friendly, just that I still need to apply it to my model ..

    
asked by Ultra 30.11.2017 в 21:57
source

0 answers