Giter Club home page Giter Club logo

curl2pyreqs's Introduction

curl2pyreqs

A library to convert curl to python requests file.

Requirement

Python >= 3.6

pyperclip >= 1.8.0

rich >= 9.13.0

On Linux, xclip or xsel needed:

sudo apt-get install xclip
or
sudo apt-get install xsel

Install

$ pip install curl2pyreqs

Usage

Use as binary

  • Export curl request file to python script.
$ curl2pyreqs -F example.curl
Convertion Finished.
Please open example.py to check the code.
  • Convert curl request in the clipboard and paste the requests code back
$ curl2pyreqs
Convertion Finished.
Now requests code is copyed in your clipboard.

Use by importing

  • Convert a curl string to python-requests, copyed from Chrome or Firefox:
>>> from curl2pyreqs.ulti import parseCurlString
>>> output = parseCurlString("""curl -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'accept-language: en-US,en;q=0.5' --compressed -H 'upgrade-insecure-requests: 1' -H 'te: trailers' https://pypi.org/""")
>>> print(output)
  • Convert curl file stream to python-requests, copyed from Chrome or Firefox:
>>> from curl2pyreqs.ulti import parseCurlFile
>>> output = parseCurlFile('./example.curl')
>>> print(output)

README_CN

中文版说明

curl2pyreqs's People

Contributors

knightz1224 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

curl2pyreqs's Issues

Error

from curl2pyreqs import parseCurlString
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'parseCurlString' from 'curl2pyreqs' (C:\ProgramData\Anaconda3\lib\site-packages\curl2pyreqs_init_.py)

post请求不能正确解析data参数

感谢大佬的分享,很好用。但是有个bug, post请求无法正确生成,缺少了data参数,比如下面这个curl。
来自https://www.iqihang.com/courselist这个网站
image

curl 'https://www.iqihang.com/api/v2/product/product-for-list/search-product-with-activity-info' \
  -H 'Connection: keep-alive' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'EagleEye-SessionID: g0kC4r8qgkn0mp1m11py0ebeORme' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'EagleEye-pAppName: ah4dzf6mjw@7edb64cda121776' \
  -H 'EagleEye-TraceID: 61c61feb1627023911944100421776' \
  -H 'Origin: https://www.iqihang.com' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Referer: https://www.iqihang.com/courselist' \
  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \
  -H 'Cookie: Hm_lvt_2d1f9d97bbf037a2066e67f718a18093=1626772826; Hm_lvt_c0950c4366376d203c68fb5cde1b2c88=1626772826; DELOP_391=cfa4d910-af55-4112-b7d6-5103275635dc; SESSION=ZDhjY2IwNjUtMGMzZS00ZmQzLWE1ODAtZTBmMjNmYTAyYzZl; _bl_uid=b2k63r6sbRnu21j4Oe10rm6872e4; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2217ac3376baf428-05ba3fb96f800d-34647600-2073600-17ac3376bb0fa7%22%2C%22%24device_id%22%3A%2217ac3376baf428-05ba3fb96f800d-34647600-2073600-17ac3376bb0fa7%22%2C%22props%22%3A%7B%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; gr_user_id=f9718ad6-d4d9-429e-86b6-21e61602daff; client_id=72827505; Hm_lpvt_2d1f9d97bbf037a2066e67f718a18093=1627021195; acw_tc=65c86a0916270239103797398eb2c86843ab2a245ffbc19ba920de87fdc170; Hm_lpvt_c0950c4366376d203c68fb5cde1b2c88=1627023912' \
  --data-raw '{"sort":"CREATE_TIME_DESC","year":"","catalogId":"","classType":"","pageIndex":0,"pageSize":9,"catalogIds":null}' \
  --compressed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.