Библиотека запросов Python не может выполнить успешный POST (контроллер двигателя Nanotec)Python

Программы на Python
Гость
Библиотека запросов Python не может выполнить успешный POST (контроллер двигателя Nanotec)

Сообщение Гость »


У меня есть контроллер двигателя, на котором запущен веб-сервис REST, которым я хочу управлять с помощью Python.
Я могу успешно выполнять запросы GET, используя библиотеку запросов Python. Однако я не могу выполнять запросы POST. Выдает следующую ошибку:

Код: Выделить всё

requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
I suspect that the web service crashes because I sometimes have to restart the motor controller to get GET requests working again. Here is the python code I am using to perform the POST:

Код: Выделить всё

import requests

url = 'http://192.168.178.199/od/607A/00'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = '00000002'

response = requests.post(url, headers=headers, data=data)

print(response.content)
I am however able to successfully perform POST requests using the following Curl command:

Код: Выделить всё

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -i 'http://192.168.178.199/od/607A/00' --data '"00000003"'

HTTP/1.0 200 OK
Server: uip/1.0
Cache-Control: no-cache, no-store, private
Content-type: application/json
The python code should be exactly the same right? What am I missing?
FYI: The motor controller I am using is a nanotec n5-2-3. Manual with info on the REST service can be found here:
https://en.nanotec.com/fileadmin/files/ ... V3.2.0.pdf


Источник: https://stackoverflow.com/questions/759 ... controller

Вернуться в «Python»