- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基于 URL 和用户输入数据构建 CURL 命令的 python 代码
我有
import os
print ("______________\n")
print " 1.GET "
print " 2.POST "
print " 3.PUT "
print " 4.DELETE "
print ("______________\n")
http = int(raw_input("Select your option : "))
url = raw_input("Paste Your URL : ")
if not http:
http = 3
if http == 1:
cmd = 'curl '+ url
elif http == 2:
data = raw_input("Paste Your Data : ")
cmd = 'curl -g -X POST -H "Content-Type:application/json" -d \''+data+'\' ' + url
elif http == 3:
data = raw_input("Paste Your JSON Data: ")
cmd = 'curl -g -X PUT -H "Content-Type:application/json" -d \''+data+'\' ' + url
else:
cmd = 'curl -g -X DELETE ' + url
print ("_________________________________________\n")
print '\n'
print cmd
print '\n'
print ("_________________________________________\n")
run = raw_input("Do you want to run it ? [y/n]: ")
print '\n'
if run == 'y':
os.system(cmd+'\n')
print '\n'
else:
os.system("clear")
sys.exit()
python get_curl.py
______________
1.GET
2.POST
3.PUT
4.DELETE
______________
Select your option : 3
Paste Your URL : http://172.19.242.32:1234/vse/vcpe/002233445567/vlan/104/device/000011223350/duration
Paste Your Data : {"acl_mode": 2, "portal_url": "http://localhost:8888/captive-portal?client_mac=$MAC&ap=$AP-MAC", "duration": 120 }
_________________________________________
curl -g -X PUT -H "Content-Type:application/json" -d '{"acl_mode": 2, "portal_url": "http://localhost:8888/captive-portal?client_mac=$MAC&ap=$AP-MAC", "duration": 120 }' http://172.19.242.32:1234/vse/vcpe/002233445567/vlan/104/device/000011223350/duration
_________________________________________
Do you want to run it ? [y/n]: y
{ "status": 201, "message": "Processed cpe HNS device duration message" }
然后,我把它放在github gist上,这样我就可以分享了
链接=
执行要点
curl "https://gist.githubusercontent.com/bheng/b23d775ee7b106cd7cc0ae5ac71b81a9/raw/c6ecd3ed7bc04699d73e1b9ed521f481ac6a41c4/get_curl.py" -s -N | python
结果
______________
1.GET
2.POST
3.PUT
4.DELETE
______________
Select your option : Traceback (most recent call last):
File "<stdin>", line 11, in <module>
EOFError: EOF when reading a line
为什么我的结果与在本地 Mac 上运行的结果不同?
我该如何预防?
最佳答案
由于您将 curl
命令通过管道传输到 python
,标准输入连接到管道,而不是用户的终端。
您可以使用 bash process substitution使 curl 命令显示为文件名参数,而不是从标准输入读取它。
python <(curl "https://gist.githubusercontent.com/bheng/b23d775ee7b106cd7cc0ae5ac71b81a9/raw/c6ecd3ed7bc04699d73e1b9ed521f481ac6a41c4/get_curl.py" -s -N)
关于python - EOFError : EOF when reading a line only when execute it via curl 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40293959/
从 Rails 控制台使用 MailChimp gem 时出现间歇性错误。 这是错误: Excon::Errors::SocketError: EOFError (EOFError) from /
我正在使用 tkinter 和 urllib 制作这个程序,它应该像一个下载管理器。在我几乎完成该程序后,我意识到我没有为下载定义取消按钮。在深入研究之后,我发现了多处理(在此之前我只是使用线程),显
当我尝试 chown 一个目录时,Fabric 给我一个 EOFError。只有当我从 fabric 之前运行的 python 脚本运行子进程时才会发生。 来 self 的 fabfile: ...
当我使用来自其他脚本的子进程启动我的 python3 脚本时,出现以下错误: Select the keyword preset you want to use:Traceback (most rec
编辑:我很蠢 对不起大家。我的循环不工作的原因是一个极其愚蠢的原因;我的 pickle.dump() 参数顺序错误。 操作 第一次 pickle 物体,抱歉,如果这是一个棘手的问题;看过各种其他 EO
我有一堆客户端通过 0MQ 连接到服务器。我有一个管理器队列,用于工作池与每台客户端计算机上的主进程进行通信。 在一台有 250 个工作进程的客户端机器上,我几乎立即看到一堆 EOFError。它们发
这可能会重复,但现有的答案都没有解决我的问题。 因此,我使用的是 Python 2.7,每当我尝试此操作时都会收到此错误(标题): number = int(raw_input('Number : '
这个问题在这里已经有了答案: Unable to install pygame on Python via pip (Windows 10) (6 个答案) 关闭 2 年前。 我正在使用 Windo
我正在尝试使用 pickle 为我的游戏创建一个保存文件,但是当我尝试提交我的字典,然后取回该信息时,它不起作用。 import pickle data = {'health':100, 'gold'
我读取了一个只包含一行的文件。但是,在循环结束之前我无法停止读取文件。即 python 不会抛出 EOFError 异常。我的代码有什么问题吗? for x in range(5): try:
我有一个简单的程序,我使用 pygame 导入声音,但它仍然是一个 CLI 程序。每当我将它编译成一个 exe 时,当我尝试运行它时它会给我一个 EOFError,它看起来像这样 Traceback
我最近发现了 pickle,这很神奇。但是当它用于我的实际脚本时,它对我来说是错误的,用一个单项字典测试它工作正常。我的真实脚本是数千行代码,其中存储了 Maya 中的各种对象。我不知道它是否与大小有
我有几个脚本在服务器上运行,可以对各种词典进行 pickle 和 unpickle。它们都使用相同的基本代码进行 pickle ,如下所示: SellerDict=open('/home/hostad
我有以下代码片段: def database(self): databasename="" host="" user="" password="" try:
我正在读取 CSV 作为 Spark DataFrame 并对其执行机器学习操作。我不断收到 Python 序列化 EOFError - 知道为什么吗?我认为这可能是一个内存问题——即文件超出了可用
当我运行下面的代码时,我收到此错误消息“EOFError: Ran out of input”这是什么意思??怎么才能矫正??以及如何在屏幕上输出记录的详细信息。 import pickle # th
为什么我在运行 django 服务器时会出现以下错误,我该如何解决? : EOFError: marshal data too short 细节 Performing system checks...
尝试创建用户时,我在生产中遇到此错误(我正在使用devise gem)。 EOFError (end of file reached): 我之前遇到此问题,这是由于我使用zoho mail的smtp设
我正在努力解决这一问题,我们将不胜感激! 我有两个Rails应用程序,我们称它们为Client and Service,它们都是非常简单的普通REST界面-这是基本方案: 客户端向服务发出POST/r
一切正常,直到: celery beat v3.1.18 (Cipater) is starting. __ - ... __ - _ Configuration ->
我是一名优秀的程序员,十分优秀!