Py学习  »  Python

将python请求程序转换为对curl的调用

fred • 5 年前 • 1442 次点击  

我有一个python程序,它发出get请求并打印结果。有些输入是字符串列表,而不仅仅是字符串,因此我不确定如何将其转换为对curl的调用。另外,我也不确定这类东西叫什么,所以我在网上找不到任何关于它的信息。下面我举了一个很小的例子来说明我想做什么。

import requests
URL = "http://example.com/script.php"
PARAMS = {'param1':['val1','val2']}
print(requests.get(URL,PARAMS).text)

我尝试了以下方法:

curl "https://example.com/script.php?param1=['val1','val2']"  

但是我犯了个错误:

curl: (3) [globbing] bad range specification in column 40
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56972
 
1442 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Netwave
Reply   •   1 楼
Netwave    6 年前

填充 手动:

curl "http://example.com/script.php?param1=val&param2=val2"

在这种情况下:

curl "http://example.com/script.php?param1=[val1,val2]"

curl "http://example.com/script.php?param1=val1,val2"