简体   繁体   English

在Python中将Curl转换为请求

[英]Converting Curl to a Request in Python

I am trying to work out how to convert curl request to python, but I am not 100% sure what is what. 我正在尝试找出如何将curl请求转换为python,但是我不确定100%是什么。 How do you pull apart a curl request so it will work with a pyhton request (I would prefer not use any 3rd party packages) 您如何拆分curl请求,使其与pyhton请求一起使用(我不希望使用任何第三方软件包)

curl -i -XPOST 'http://10.16.1.35:8086/write?db=maintenance' --data-binary 'temperature,pi=Raspberry,sensor=Blue value=64.50 1490643440916250112'

and

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt

I don't understand what elements in here are what so I can convert the request. 我不明白这里的元素是什么,所以我可以转换请求。

Thankyou! 谢谢!

I believe you can do this in two ways. 我相信您可以通过两种方式做到这一点。

  1. Using pycurl library which acts like an interface to cURL library. 使用pycurl库,其作用类似于cURL库的接口。 You can take a look at the documentation here 您可以在这里查看文档
  2. You can send a http request with content type, header and parameters using the requests library for python. 您可以使用python请求库发送带有内容类型,标头和参数的http请求。 You can take a look at their documentation here . 您可以在这里查看他们的文档。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM