[英]How to convert curl command in shell script to python using requests library
[英]how to convert curl command to python3 requests
谁能告诉我如何将下面的这个 CURL 命令转换为 Python3 请求模块?
卷曲命令:
curl --header "Accept=application/json" --form
print_file=@a.gcode http://189.167.1.103/print_file_uploads
实际上我必须将 Gcode 文件上传到 3D 打印机。
我成功地使用了模块 OS。 这是我的做法。
成功:
import os
ip_address = 189.167.1.103
file_name = "D:\networking\a.gcode"
os.system("curl --header "Accept=application/json" --form
print_file=@%shttp://%s/print_file_uploads"%(file_name,ip_address))
但我不想用 OS 模块来完成。 你能帮我在 python3 请求中实现相同的吗?
首先你可以阅读这个
因此,请求的示例是:
import requests
response = requests.get('https://github.com/timeline.json')
response.json()
你可能的解决方案是这样的:
import requests
url = 'http://189.167.1.103/print_file_uploads'
payload = open("D:\networking\a.gcode")
headers = {'Accept: application/json'}
response = requests.post(url, data=payload, headers=headers)
这可能有效-
进口请求
access_token = 'xxxx' device_id = 'xxxx'
地址 = ' https://api.spark.io/v1/devices/ {0}/update/'.format(device_id) 数据 = {'access_token': access_token, 'args': '000000000000000'}
r = requests.post(地址,数据=数据)
打印(r.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.