Skip to main content

Convert curl command to json data

Project description

Trans curl request to json data

将参数转化为json 的时候尽量使用 -- 之后的值,作为字典的键。 这个库的目的是将curl 发送请求的参数转化为json 格式,方便在python 中使用。

curl 功能很强大,支持的参数也很多,这里只做了部分的解析

重点放在curl HTTP发送请求的方面.

其他一些特性,--ipv4,--ipv6,本地文件读取,指定dns 寻址服务器 DoH,ftp 等协议暂未支持

支持的参数

  • -X, --request 支持的请求方法,

  • --http2 是否使用http2 协议 默认为否

  • -d,--data 支持, 支持在一行命令中多次使用-d 参数,此时HTTP 请求头中 Content-Type : application/x-www-form-urlencoded

    使用该参数,请求自动转化为POST.

  • -H,--header 添加HTTP请求头,支持多行

  • -I,--head 发送HEAD请求,并打印header,支持

  • -s,--silent, 不输出任何东西,只返回HTTP 头

  • -v, --verbose 输出通信的整个过程,用于调试

  • -b, --cookie cookie 支持多个-b 参数,不支持文件读取

  • -A, --user-agent 设置User-Agent,curl 默认的User-Agent 为 curl/version,本项目默认为空

  • --compressed 是否压缩请求

  • -k, --insecure 允许不验证服务器的证书

  • -u, --user 用户名:密码

  • -L, --location 允许自动跟随重定向

  • -I,--include 打印头信息

  • -x--proxy 使用代理 代理 格式为:hostname:port,如果没有scheme 默认使用http

  • -U, --proxy-user 代理用户名密码 ,格式为:username:password 如果有会自动将账号密码添加到代理url 中

  • -u, --user basic 认证,格式为:username:password,输出为headers 中的Authorization

  • --connect-timeout 连接超时时间

  • --referer 请求头中的referer

usage

  1. 命令行中使用
python -m curl_to_json  curl_to_json curl -X GET http://example.com
  1. 也可以直接使用
curl_to_json curl -X GET http://example.com
  1. 也可以使用 以下格式
curl_to_json "curl -X GET http://example.com"
  1. 在python 代码中使用
from curl_to_json import parse

cmd = 'curl -X GET http://example.com'

print(parse(cmd))

Reference

1. curl 的用法指南

2. Linux命令大全-curl

3. Uncurl

4. curl 在线手册

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curl_to_json-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curl_to_json-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file curl_to_json-0.1.0.tar.gz.

File metadata

  • Download URL: curl_to_json-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.18 Darwin/24.1.0

File hashes

Hashes for curl_to_json-0.1.0.tar.gz
Algorithm Hash digest
SHA256 467270f94e7aab2af71e927fd6e310b1ee0cdabaa380b53bdf7607bc30c37f26
MD5 c17c7cdd9d67c1f2e20c8e24186bded9
BLAKE2b-256 df93bae9a22b311b067e421a2ee29ce3594de687ec00ca1973fd632c5adee24d

See more details on using hashes here.

File details

Details for the file curl_to_json-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: curl_to_json-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.18 Darwin/24.1.0

File hashes

Hashes for curl_to_json-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 413ca8999f9dc4d2fe00607bd1d1cd58791ae0f8b10ddb56f38975999a4f9eff
MD5 11693abb2899a4959d2c12cf5a79bb9c
BLAKE2b-256 8f919ac26fe51e5821d75287657c97c06c0cbb0350faef12b7158a6cc54810ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page