requests_toolbelt Documentation



Similar documents
COMP 112 Assignment 1: HTTP Servers

MatrixSSL Getting Started

Factory Application Certificates and Keys Products: SB700EX, SB70LC

smtplib SMTP protocol client

pyownet Documentation

The HTTP Plug-in. Table of contents

Instructions on TLS/SSL Certificates on Yealink Phones

HOST EUROPE CLOUD STORAGE REST API DEVELOPER REFERENCE

socketio Documentation

Django Assess Managed Nicely Documentation

Lab Exercise SSL/TLS. Objective. Requirements. Step 1: Capture a Trace

monoseq Documentation

Package httprequest. R topics documented: February 20, 2015

Using Caché Internet Utilities

GDC Data Transfer Tool User s Guide. NCI Genomic Data Commons (GDC)

Guzzle Release December 19, 2015

CumuLogic Load Balancer Overview Guide. March CumuLogic Load Balancer Overview Guide 1

Beyond The Web Drupal Meets The Desktop (And Mobile) Justin Miller Code Sorcery Workshop, LLC

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on Mail Tab.

DevKey Documentation. Release 0.1. Colm O Connor

Application Detection

How to configure SSL proxying in Zorp 6

EHR OAuth 2.0 Security

BCR Export Protocol SHAPE 2012

A Java proxy for MS SQL Server Reporting Services

MarkLogic Server. Node.js Application Developer s Guide. MarkLogic 8 February, Copyright 2016 MarkLogic Corporation. All rights reserved.

The Internet of Unpatched Things

Owner of the content within this article is Written by Marc Grote

3.2: Transport Layer: SSL/TLS Secure Socket Layer (SSL) Transport Layer Security (TLS) Protocol

User Guide - Table of Contents

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

Contents. 2 Alfresco API Version 1.0

Django Two-Factor Authentication Documentation

Protocol-Level Evasion of Web Application Firewalls

Lab Exercise SSL/TLS. Objective. Step 1: Open a Trace. Step 2: Inspect the Trace

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

vmprof Documentation Release 0.1 Maciej Fijalkowski, Antonio Cuni, Sebastian Pawlus

Cloud storage with Apache jclouds

Gillcup Documentation

Nuance Mobile Developer Program. HTTP Services for Nuance Mobile Developer Program Clients

Customer Tips. Xerox Network Scanning HTTP/HTTPS Configuration using Microsoft IIS. for the user. Purpose. Background

ATS Test Documentation

Bitcoin Payment Gateway API

How To Start Libres3 On A Ubuntu (Sx) Or Libres 3 (S3) On A Raspberry Web 2.5 (Sbt) Or Sbt (Sos) On Ubuntu 8

HTTP connections can use transport-layer security (SSL or its successor, TLS) to provide data integrity

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on. User Information

Lektion 2: Web als Graph / Web als System

How To Burp David Brown

MatrixSSL Developer s Guide

How to configure HTTPS proxying in Zorp 6

, SNMP, Securing the Web: SSL

API documentation - 1 -

Access Manager 4.1 Service Pack 2 (4.1.2) supersedes Access Manager 4.1 Service Pack 1 Hotfix 1 (4.1.1 HF1).

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on Mail Tab.

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

Grandstream Networks, Inc. GXP2130/2140/2160 Auto-configuration Plug and Play

Outline Definition of Webserver HTTP Static is no fun Software SSL. Webserver. in a nutshell. Sebastian Hollizeck. June, the 4 th 2013

Gigaset IP and IP-PRO Phones Provisioning / Remote Management. last modifications by J. Stahl, Bocholt, January the 18 th 2011

How to configure SSL proxying in Zorp 3 F5

Dashlane Security Whitepaper

µtasker Document FTP Client

Security Issues in Web Programming. Robert M. Dondero, Ph.D. Princeton University

ICE Trade Vault. Public User & Technology Guide June 6, 2014

Introduction to the. Barracuda Embedded Web-Server

Wireless Security Camera with the Arduino Yun

Enabling Security Features in Firmware DGW v2.0 June 22, 2011

Axway API Gateway. Version 7.4.1

Kerberos and Single Sign On with HTTP

Certified The Grinder Testing Professional VS-1165

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

SBClient SSL. Ehab AbuShmais

Low-Level TLS Hacking

Web Services for Management Perl Library VMware ESX Server 3.5, VMware ESX Server 3i version 3.5, and VMware VirtualCenter 2.5

THE PROXY SERVER 1 1 PURPOSE 3 2 USAGE EXAMPLES 4 3 STARTING THE PROXY SERVER 5 4 READING THE LOG 6

How to configure HTTPS proxying in Zorp 5

SSL Enforcer Documentation

[SMO-SFO-ICO-PE-046-GU-

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

SIM Configuration Guide. February 2015 Version 1 Document Reference: 8127

HTTPS is Fast and Hassle-free with CloudFlare

Authorize Sauce Documentation

Lecture 11 Web Application Security (part 1)

Crypto at Scale. Brian Sniffen

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Features Overview Guide About new features in WhatsUp Gold v14

PROFESSIONAL. Node.js BUILDING JAVASCRIPT-BASED SCALABLE SOFTWARE. Pedro Teixeira WILEY. John Wiley & Sons, Inc.

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with the Zimbra Open Source and Collaboration Suite

SPARROW Gateway. Developer Data Vault Payment Type API. Version 2.7 (6293)

Benchmarking Cloud Storage through a Standard Approach Wang, Yaguang Intel Corporation

SAML single sign-on configuration overview

How to Resolve the POODLE Vulnerability in Native Connection to Oracle

DMH remote access. Table of Contents. Project : remote_access_dmh Date: 29/05/12 pg. 1

Transcription:

requests_toolbelt Documentation Release 0.1.0 Ian Cordasco, Cory Benfield March 14, 2015

Contents 1 User Guide 3 1.1 Streaming Multipart Data Encoder.................................... 3 1.2 User-Agent Constructor......................................... 4 1.3 SSLAdapter............................................... 5 1.4 GuessAuth................................................ 5 2 Indices and tables 7 i

ii

requests_toolbelt Documentation, Release 0.1.0 This is a collection of utilities that some users of python-requests might need but do not belong in requests proper. The library is actively maintained by members of the requests core development team, and so reflects the functionality most requested by users of the requests library. To get an overview of what the library contains, consult the user documentation. Contents 1

requests_toolbelt Documentation, Release 0.1.0 2 Contents

CHAPTER 1 User Guide The requests-toolbelt contains a number of unrelated tools and utilities for helping with use-cases that are not directly supported by the core requests library. This section of the documentation contains descriptions of the various utilities included in the toolbelt, and how to use them. 1.1 Streaming Multipart Data Encoder Requests has support for multipart uploads, but the API means that using that functionality to build exactly the Multipart upload you want can be difficult or impossible. Additionally, when using Requests Multipart upload functionality all the data must be read into memory before being sent to the server. In extreme cases, this can make it impossible to send a file as part of a multipart/form-data upload. The toolbelt contains a class that allows you to build multipart request bodies in exactly the format you need, and to avoid reading files into memory. An example of how to use it is like this: from requests_toolbelt import MultipartEncoder import requests m = MultipartEncoder( fields={ field0 : value, field1 : value, field2 : ( filename, open( file.py, rb ), text/plain )} ) r = requests.post( http://httpbin.org/post, data=m, headers={ Content-Type : m.content_type}) The MultipartEncoder has the.to_string() convenience method, as well. This method renders the multipart body into a string. This is useful when developing your code, allowing you to confirm that the multipart body has the form you expect before you send it on. The toolbelt also provides a way to monitor your streaming uploads with the MultipartEncoderMonitor. 1.1.1 Monitoring Your Streaming Upload If you need to stream your multipart/form-data upload then you re probably in the situation where it might take a while to upload the content. In these cases, it might make sense to be able to monitor the progress of the upload. For this reason, the toolbelt provides the MultipartEncoderMonitor. The monitor wraps an instance of a MultipartEncoder and is used exactly like the encoder. It provides a similar API with some additions: The monitor accepts a function as a callback. The function is called every time requests calls read on the monitor and passes in the monitor as an argument. 3

requests_toolbelt Documentation, Release 0.1.0 The monitor tracks how many bytes have been read in the course of the upload. You might use the monitor to create a progress bar for the upload. Here is an example using clint _ which displays the progress bar. To use the monitor you would follow a pattern like this: from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor import requests def my_callback(monitor): # Your callback function pass e = MultipartEncoder( fields={ field0 : value, field1 : value, field2 : ( filename, open( file.py, rb ), text/plain )} ) m = MultipartEncoderMonitor(e, my_callback) r = requests.post( http://httpbin.org/post, data=m, headers={ Content-Type : m.content_type}) If you have a very simple use case you can also do: from requests_toolbelt import MultipartEncoderMonitor import requests def my_callback(monitor): # Your callback function pass m = MultipartEncoderMonitor.from_fields( fields={ field0 : value, field1 : value, field2 : ( filename, open( file.py, rb ), text/plain )}, callback=my_callback ) r = requests.post( http://httpbin.org/post, data=m, headers={ Content-Type : m.content_type}) 1.2 User-Agent Constructor Having well-formed user-agent strings is important for the proper functioning of the web. Make server administators happy by generating yourself a nice user-agent string, just like Requests does! The output of the user-agent generator looks like this: >>> import requests_toolbelt >>> requests_toolbelt.user_agent( mypackage, 0.0.1 ) mypackage/0.0.1 CPython/2.7.5 Darwin/13.0.0 The Python type and version, and the platform type and version, will accurately reflect the system that your program is running on. You can drop this easily into your program like this: from requests_toolbelt import user_agent from requests import Session 4 Chapter 1. User Guide

requests_toolbelt Documentation, Release 0.1.0 s = Session() s.headers = { User-Agent : user_agent( my_package, 0.0.1 ) } r = s.get( https://api.github.com/users ) This will override the default Requests user-agent string for all of your HTTP requests, replacing it with your own. 1.3 SSLAdapter The SSLAdapter is the canonical implementation of the adapter proposed on Cory Benfield s blog, here. This adapter allows the user to choose one of the SSL/TLS protocols made available in Python s ssl module for outgoing HTTPS connections. In principle, this shouldn t be necessary: compliant SSL servers should be able to negotiate the required SSL version. In practice there have been bugs in some versions of OpenSSL that mean that this negotiation doesn t go as planned. It can be useful to be able to simply plug in a Transport Adapter that can paste over the problem. For example, suppose you re having difficulty with the server that provides TLS for GitHub. You can work around it by using the following code: from requests_toolbelt import SSLAdapter import requests import ssl s = requests.session() s.mount( https://github.com/, SSLAdapter(ssl.PROTOCOL_TLSv1)) Any future requests to GitHub made through that adapter will automatically attempt to negotiate TLSv1, and hopefully will succeed. 1.4 GuessAuth The GuessAuth auth type automatically detects whether to use basic auth or digest auth: from requests_toolbelt import GuessAuth import requests requests.get( http://httpbin.org/basic-auth/user/passwd, auth=guessauth( user, passwd )) requests.get( http://httpbin.org/digest-auth/auth/user/passwd, auth=guessauth( user, passwd )) This requires an additional request in case of basic auth, as usually basic auth is sent preemptively. 1.3. SSLAdapter 5

requests_toolbelt Documentation, Release 0.1.0 6 Chapter 1. User Guide

CHAPTER 2 Indices and tables genindex modindex search 7