Hey!
Ich habe folgendes programm:
from socket import AF_INET, SOCK_STREAM, socket as sock
def httpRequest(host:str, port:int, subsite:str) -> None:
client = sock(AF_INET, SOCK_STREAM)
client.connect((host, port))
request = f"GET {subsite} HTTP/1.1\r\nHost:{host}\r\n\r\n"
client.send(request.encode())
response = client.recv(4096).split(b'\r\n')
with open('img.png', 'wb') as file:
file.write(response[len(response) - 1])
httpRequest('0.0.0.0', 80, '/-wvhttp-01-/getoneshot')
Mit dem ich bilder einer IP Webcam runterladen möchte.
Allerdings sieht img.png nicht aus wie das Original und ist zur hälfte schwarz und zur anderen Grau.
Die anwort des servers (zeile 8) sieht so aus:
[b'HTTP/1.0 200 OK', b'Date: Mon, 23 May 2022 14:52:17 GMT', b'Server: VB/3.6', b'Connection: close', b'Pragma: no-cache', b'Cache-Control: no-cache', b'Expires: Thu, 01 Jan 1970 00:00:01 GMT', b'Livescope-Status: 0', b'Livescope-Channel: 1', b'Livescope-Frame-Number: 1', b'Accept-Ranges: none', b'Content-Type: image/jpeg', b'Content-Length: 2599', b'',
b'\xff\xd8\xff\xe0\x00>VB\x00\x01\x13\xb0F\xc9\x10\x1e\x00\x01b\x8b\x9f\xa1\x02\x1c2\x07\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01@\x00\xf0\x01\ und noch einiges mehr an hex']
Wenn ich einfach nur
$ wget http://0.0.0.0/-wvhttp-01-/getoneshot
Ins Terminal eingebe wird das bild Problemlos heruntergeladen.