A library wrapper for PyCurl combained with WinAPI calls to support automatic proxy detection with a 'requests'-like infterface
Project description
besocurl
A library for HTTP / HTTPs requests that supports SSPI and PAC file parsing(Automatic proxy settings detection)
besoCurl by Omri Baso
Date: 21/10/2020
All right reserved to Omri Baso for this library
credits for pieces of code taken from other places are inside the code
some code was taken from the Px project
https://github.com/genotrance/px/blob/master/px.py
Download pycurl from: https://dl.bintray.com/pycurl/pycurl/
Dependencies:
pycurl-7.43.0.2 (I added the installiation for Windows that matchs python 3.6 because thats the one i used to build this library)
python 3.x
Installtion:
Windows:
1. Install pycurl.exe from here to your python version https://dl.bintray.com/pycurl/pycurl/
Linux:
1. apt install libcurl4-openssl-dev libssl-dev
2. apt install python-dev python3-dev build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev zlib1g-dev
3. python3 -m pip install setuptools wheel pycurl
Technical Information
the besoCurl project comes to make Pycurl more human usable while implmenting more automatic approch to the library, the library supports SSPI authentication to proxies over HTTP or HTTP(s) besoCurl has simple functions such as:
import besoCurl
def main():
url = 'http://192.168.189.136/'
useragents = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; Safari/537.36'
headers = ["Accept: OmriBeso", "Content-type: application/json"]
r = besoCurl.get(url, headers=headers, user_agent=useragents, auto_detect_proxy=True)
print(r.text)
main()
OR for a post request
import besoCurl
def main():
url = 'http://192.168.189.136/'
useragents = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; Safari/537.36'
headers = ["Accept: OmriBeso", "Content-type: application/json"]
r = besoCurl.post(url, data=data, headers=headers, user_agent=user_agent, auto_detect_proxy=True)
print(r.text)
main()
the code infront of you will return the HTML content of the url inserted into the function,
user the User-Agent set to it and the headers.
also - auto_detect_proxy=True
will try to fetch the windows settings for accessing the internet.
if a PAC file is configured it will download it and parse the Javascript in order for you go through
the proxy, if a PAC file is configured AND a manual proxy is set, it will choose the PAC path instead.
if only a manual proxy is set it will use it, if no proxy is configured i will not use any proxies and go directly to the internet.
if a proxy is set, the HTTP request will use SSPI to authenticate to the proxy without entering any credentials.
More Information about how it works: https://docs.microsoft.com/en-us/windows/win32/rpc/security-support-provider-interface-sspi-
In general i recommend to use auto_detect_proxy=True
all the time.
you can also set a proxy manully when invoking a request as the variables proxies=[("127.0.0.1", 8080)]
proxies must have the format mentioned above.
TODO:
- add WPAD (Auto Detect Settings support) - DONE 06/01/2021,
- add PUT method, - DONE 06/01/2021
- and multipart forms on POST requests
- add session options so request will not authenticate everyime they are sent all over again
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file besocurl-0.0.4.tar.gz
.
File metadata
- Download URL: besocurl-0.0.4.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1f61b319bb98833dbf9284f04f9fb88b4ae99d5dac2e38ed291a43b2a9791dd |
|
MD5 | 2a870c59d7b699b702dbb62ee88c9902 |
|
BLAKE2b-256 | 023b4b689d363a54703bfc84ea9d11f66de8cb0eee31fe384142b9ede4e28823 |
File details
Details for the file besocurl-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: besocurl-0.0.4-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b55f2ed2bef847ee87064433b6b8881b624639a2ce194ce1efd7cfa69d51b36 |
|
MD5 | 05a8d1b9a0e4413e981520d823d68bb3 |
|
BLAKE2b-256 | 3e11052a2eb8560d17295b635ed22307674b96e0c3d7c11f13e69b7a5ca380bc |