【发布时间】:2015-02-01 10:49:06
【问题描述】:
我对 shell 或 python 脚本没有太多经验,所以我正在寻找一些关于如何实现这一点的帮助。
目标:
将参数传递给将用于执行 cURL Post 请求或 python post 请求的 shell 或 python 脚本文件。
假设我走python路线,文件名是api.py
import json,httplib
connection = httplib.HTTPSConnection('api.example.com', 443)
connection.connect()
connection.request('POST', '/message', json.dumps({
"where": {
"devicePlatform": "andriod"
},
"data": {
"body": "Test message!",
"subject": "Test subject"
}
}), {
"X-Application-Id": "XXXXXXXXX",
"X-API-Key": "XXXXXXXX",
"Content-Type": "application/json"
})
result = json.loads(connection.getresponse().read())
print result
我将如何为正文和主题值传递参数,以及通过命令行看起来如何?
谢谢
【问题讨论】:
-
好吧,请稍等一下:如何获取 Python 脚本的命令行参数?
标签: python shell curl command-line-arguments