mgkit.net.utils module

Utility functions for the network package

mgkit.net.utils.url_open(url, data=None, headers=None, agent=None, get=True, stream=False)[source]

Changed in version 0.3.4: now uses requests

Parameters
  • url (str) – url to request

  • data (str) – parameters to pass to the request

  • headers (dict) – any additional headers

  • agent (str) – user agent to use

  • get (bool) – True if the request is a GET, False for POST

  • stream (bool) – returns an iterator to stream over

  • url – url to request

  • data – data to add to the request

  • compress (bool) – if the response should be compressed

  • agent – if supplied, the ‘User-Agent’ header we’ll be added to the request

Returns

the response handle

mgkit.net.utils.url_read(url, data=None, agent=None, headers=None, get=True)[source]

Changed in version 0.3.4: now uses requests, removed compressed and added headers, get

Opens an URL and reads the

Wrapper of url_open() which reads the full response

Parameters
  • url (str) – url to request

  • data (dict or None) – data to add to the request

  • headers (dict or None) – additional headers

  • agent (str or None) – if supplied, the ‘User-Agent’ header we’ll be added to the request

  • get (bool) – uses a GET operation if True, POST if False

Returns

the response data

Return type

str