Skip to main content

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 在线手册

Metadata

Release files for curl-to-json 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curl-to-json 0.1.0
File Size Uploaded Provenance Actions
curl_to_json-0.1.0.tar.gz 4.3 kB Without provenance Details for curl_to_json-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for curl-to-json 0.1.0
File Interpreter ABI Platform Actions
curl_to_json-0.1.0-py3-none-any.whl Python 3 none any Details for curl_to_json-0.1.0-py3-none-any.whl

Total release size: 9.5 kB

Release files / curl_to_json-0.1.0.tar.gz

Download URL curl_to_json-0.1.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
467270f94e7aab2af71e927fd6e310b1ee0cdabaa380b53bdf7607bc30c37f26
BLAKE2b-256 checksum
How to use checksums
df93bae9a22b311b067e421a2ee29ce3594de687ec00ca1973fd632c5adee24d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.18 Darwin/24.1.0

Release files / curl_to_json-0.1.0-py3-none-any.whl

Download URL curl_to_json-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
413ca8999f9dc4d2fe00607bd1d1cd58791ae0f8b10ddb56f38975999a4f9eff
BLAKE2b-256 checksum
How to use checksums
8f919ac26fe51e5821d75287657c97c06c0cbb0350faef12b7158a6cc54810ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.8.18 Darwin/24.1.0

Security for curl-to-json 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page