运行动态curl请求的python脚本
Python新手,这里是我当前的脚本:运行动态curl请求的python脚本,python,bash,curl,Python,Bash,Curl,Python新手,这里是我当前的脚本: #!/usr/bin/env python import os import time import datetime import subprocess ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime(%Y%m%d) 我的curl命令: curl -i -k -H -o <timestamp>.txt "Accept: application/json"
#!/usr/bin/env python
import os
import time
import datetime
import subprocess
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime(%Y%m%d)
我的curl命令:
curl -i -k -H -o <timestamp>.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from=<timestamp>
那没用,然后我试着用
subprocess.call(<same curl command as above>)
subprocess.call()
但这不起作用
我尝试了bash中的curl命令,它运行正常,我可以获得时间戳来显示我需要它的方式。我就是想不出如何把一切联系起来。在我发布这篇文章之前,我确实试着自己去弄清楚,但这是我第一次真正进入python,所以我对什么可行什么不可行的知识非常有限。寻求帮助!谢谢
my_command = 'curl -i -k -H -o {timestamp}.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from={timestamp}'.format(timestamp=123456)
os.system(my_command)
应该很好。。。我不完全确定你为什么要在python中这样做。。。但是这应该允许您没有问题我只会在shell的curl
调用中使用$(date+%Y%m%d”)
,不会编写任何Python代码。
my_command = 'curl -i -k -H -o {timestamp}.txt "Accept: application/json" -H "Content-Type: application/json" -H "appID:******" -H "appKey:*******" -X GET https://*****.com/csOpen/workplace/hr/v1/employees_s?type=EMP&location=******&term_from={timestamp}'.format(timestamp=123456)
os.system(my_command)