Skip to content

HTTPConnection error #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tapsystem opened this issue Apr 6, 2025 · 1 comment
Closed

HTTPConnection error #713

tapsystem opened this issue Apr 6, 2025 · 1 comment

Comments

@tapsystem
Copy link

tapsystem commented Apr 6, 2025

Hello,

i don't really know if it's a bug or a mistake that i made, but like message write to report a bug, i do it...

Error message :

Exception in <file.export_frigate_timelapse.export_frigate_timelapse> line 93: response = requests.request("POST", url, headers=headers, data=payload) ^ RuntimeError: Caught blocking call to putrequest with args (<urllib3.connection.HTTPConnection object at 0x7fde71768230>, 'POST', '/api/export/cam_cuisine/start/1743921486/end/1743944886') inside the event loop by custom integration 'pyscript' at custom_components/pyscript/eval.py, line 1983: return func(*args, **kwargs). (offender: /usr/local/lib/python3.13/site-packages/urllib3/connection.py, line 219: return _HTTPConnection.putrequest(self, method, url, *args, **kwargs)), please create a bug report at https://github.com/custom-components/pyscript/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#putrequest

script :

import http.client
import json
import string
import datetime
from random import randrange

#definition des valeur par defaut pour la fonction si pas transmises
_now = int(str(datetime.datetime.now().timestamp()).split('.')[0])
_start = _now - (6*60*60) #6 heure en seconde


@service
def export_frigate_timelapse (camera_name='cam_cuisine', start_time = _start , end_time = _now ):

    # Fct de log
    def write_log(_str):
        target = 'input_text.logbook_tszone_default'
        inputState = '[ PYSCRIPT ] [ DEBUG ] : FrigateTimelapse: ('+str(randrange(10)) +'): '+ str(_str)
        state.set(target, inputState)

    write_log('start_time:'+str(start_time))
    write_log('end_time:'+str(end_time))
    conn = http.client.HTTPSConnection("frigate.XXXXXX.ovh") 
    payload = json.dumps({
        "playback": "timelapse_25x",
        "source": "recordings",
        "name": "string",
        "image_path": "string"
    })
    #write_log('payload:'+str(payload))
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    #write_log('headers:'+str(headers))
    conn.request("POST", ("/api/export/:"+camera_name+"/start/:"+str(start_time)+"/end/:"+str(end_time)), payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))

@craigbarratt
Copy link
Member

You can't make blocking calls in pyscript. See the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants