gs.form API Reference¶
The package exports the following API symbols.
-
gs.form.post_multipart(netloc, selector, fields, files=None, usessl=False)[source]¶ Post fields and files to an http host as
multipart/form-data.Parameters: - netloc (str) – The netloc (
hostorhost:port). - selector (str) – The path to the form that will be posted to.
- fields (list) – A sequence of
(name, value)2-tuple elements for regular form fields. - files (list) – A sequence of
(name, filename, value)3-tuple elements for data to be uploaded as files - usessl (bool) –
Trueif TLS should be used to communicate with the server.
Returns: The reponse-status
Return type: Example: Post three normal form fields (
parrot,piranah, andethyl) and one file (the text filerule.txt, sent as theunwrittenform field) toexample.comon port2585, using normal HTTP rather than TLS (the default):fields = [('parrot', 'dead'), ('piranha', 'brother'), ('ethyl', 'frog')] files = [('unwritten', 'rule.txt', 'This is a transgression.')] r = post_multipart('example.com:2585', '/form.html', fields, files) status, reason, text = r
- netloc (str) – The netloc (
-
class
gs.form.Response(status, reason, text)¶ Response from the server
-
status¶ The status code
-
reason¶ The short reason for the staus
-
text¶ The text of the document returned by the server.
-
Internals¶
-
gs.form.postmultipart.files_to_dict(files)[source]¶ Turn a list of file-info tuples into a dict for requests.post
Parameters: files (list) – A list of 3-tuples (field name, filename, data)Returns: A dictionary of files. Return type: dict The field names are returned as keys, and the file-data is represented as 2-tuples: filename, file. The data is converted from a string (bytes or Unicode) to either a
io.BytesIOorio.StringIO.