我在發佈請求時遇到了來自Web服務器的響應問題。網絡服務器是NanoDLP,我正在嘗試編寫一個腳本,用於在提交表單時加載3D打印文件。花了幾個小時閱讀論壇和「帖子」,涵蓋了這個話題,我看不出做錯了什麼。有人可以看一看,看看他們能幫助我嗎?代碼如下:服務器在發佈請求時未提交表單 - Python
import requests
machineAddr = "http://192.168.0.234"
# Get printable files from USB
urlUSBFiles = machineAddr + "/json/usb"
usbFiles = requests.get(urlUSBFiles).json()
print(usbFiles)
fileUploadName = input('What do you want to name your file?')
fileUploadData = {
'USBfile': usbFiles[1],
'Path': fileUploadName,
'ProfileID': '3',
'AutoCenter': '0',
'StopLayers': '',
'LowQualityLayerNumber': '0',
'MaskFile': '',
'MaskEffect': '',
'ImageRotate': '0'
}
print(fileUploadData)
urlAddUSBFiles = machineAddr + "/plate/add-usb"
r = requests.post(urlAddUSBFiles, data=fileUploadData)
print(r)
下面是當代碼運行響應:
['/media/usb0/DriveSleeve.stl', '/media/usb0/TestCube100um.zip']
What do you want to name your file?turbo {'USBfile': '/media/usb0/TestCube100um.zip', 'Path': 'turbo', 'ProfileID': '3', 'AutoCenter': '0', 'StopLayers': '', 'LowQualityLayerNumber': '0', 'MaskFile': '', 'MaskEffect': '', 'ImageRotate': '0'} <Response [200]> Process finished with exit code 0
感謝,
迪倫
要調用POST Web服務,您需要使用requests.post方法而不是get。 – notionquest
@notionquest是的,這是在代碼的底部完成的。第一部分讀取USB驅動器的內容 - 完美工作。第二個最後一行是給我的問題。 – Dylan144GT
什麼是錯誤信息?你能顯示錯誤信息嗎?你得到了什麼http狀態碼(即400,500等)? – notionquest