Git Product home page Git Product logo

requestify's Introduction

Description:

A scaffold to convert cURL into python requests code in few seconds

Install:

pip(3) install requestify

Usage:

There are two ways of input and output:

Input :

  • from_clipboard ย ##(windows not tested)
  • from_string('...your_string...')

output:

  • to_file('...your_file_name...')
  • to_current_file()

Examples:

1.copy cURL from Chrome

2.create a new script

import requestify

requestify.from_clipboard.to_file('new_request.py')

This will write to a new file

or

import requestify

requestify.from_clipboard.to_current_file()

This will overwrite the current file with new code

If you want to use from_string() , paste your cURL into a new string variable.

Example:
import requestify

base_string = '''

curl 'https://github.com/' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Cookie: .............' -H 'Connection: keep-alive' --compressed

'''

requestify.from_string(base_string).to_current_file()

3.run it

4.you will get this

import requests


headers = {'Pragma': 'no-cache',
           'Accept-Encoding': 'gzip, deflate, br',
           'Accept-Language': 'zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7',
           'Upgrade-Insecure-Requests': '1',
           'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36',
           'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
           'Cache-Control': 'no-cache',
           'Connection': 'keep-alive'
           }

cookies = {'_octo': '............',
           '_ga': '............',
           'user_session': '............',
           '__Host-user_session_same_site': '............',
           'logged_in': '............',
           'dotcom_user': '............',
           'tz': '............',
           '_gat': '............',
           '_gh_sess': '............'
           }

response = requests.get('https://github.com/', headers=headers, cookies=cookies)

Options:

you can set with_cookies or with_headers to False to disable cookies or headers code generation

requestify.from_clipboard.to_current_file(with_cookies=False,with_headers=False)

or

requestify.from_clipboard.to_file('new_request.py', with_cookies=False,with_headers=False)

Appendix:

you can also access the url , headers , cookies as python variables without writing them to a file

for instance:

import requestify

data = requestify.from_clipboard

print(data.url)
# https://github.com/
print(data.headers)
# {'Pragma': 'no-cache', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive'}
print(data.cookies)
# {'_octo': '............', '_ga': '............', 'user_session': '............', '__Host-user_session_same_site': '............', 'logged_in': '............', 'dotcom_user': '............', 'tz': '............', '_gat': '............', '_gh_sess': '............'}

requestify's People

Contributors

owhyy avatar

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.