campaignmonitor / createsend-python

A Python library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-python
MIT License
57 stars 63 forks source link

Add timeout to CreateSendBase, passed to HTTPSConnection. #58

Closed tysonclugg closed 6 years ago

tysonclugg commented 6 years ago

This is a rework of https://github.com/campaignmonitor/createsend-python/pull/26 which was badly out of date.

The current behaviour is that the default timeout is used when API requests are made, matching whatever socket.getdefaulttimeout() returns. This patch allows setting a timeout that only affects the createsend API, so that socket.setdefaulttimeout does not have to be called.

To set a timeout for createsend (without changing the global socket default timeout), create an instance and assign a new timeout, like this:

import createsend

mailing_list = createsend.List(list_id=<list id>, auth=<credentials>, ...)
mailing_list.timeout = 10  # timeout after 10 seconds
subscribers = [subscriber for subscriber in mailing_list.active().Results]

If the timeout attribute is not set, then the previous behaviour is maintained.

tysonclugg commented 6 years ago

Coveralls failed to run in Travis with the following error:

/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. The next version of cryptography will drop support for Python 2.6
  DeprecationWarning
Submitting coverage to coveralls.io...
Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.6.9/bin/coveralls", line 11, in <module>
    sys.exit(main())
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/cli.py", line 72, in main
    result = coverallz.wear()
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/api.py", line 156, in wear
    json_string = self.create_report()
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/api.py", line 174, in create_report
    data = self.create_data()
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/api.py", line 229, in create_data
    self._data.update(self.git_info())
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/api.py", line 289, in git_info
    'id': gitlog('%H'),
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/site-packages/coveralls/api.py", line 326, in gitlog
    '--pretty=format:{}'.format(fmt))
ValueError: zero length field name in format

The tests passed, so this is a coveralls vs Python 2.6 issue. I suggest the options are drop support for 2.6, or to use an older version of coveralls for 2.6 builds.

katharosada commented 6 years ago

I created almost the same PR at the same time, but I'm happy to accept yours. I think the best strategy for the python 2.6 issues is to drop support for python 2.6.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 96.532% when pulling 55f9a0c4d2240a2f5076586aee26b0b82f658a35 on tysonclugg:issue/26-timeout-api into 9fdcb0b68fc273f88ce2800a4be52911620703c5 on campaignmonitor:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 96.532% when pulling 55f9a0c4d2240a2f5076586aee26b0b82f658a35 on tysonclugg:issue/26-timeout-api into 9fdcb0b68fc273f88ce2800a4be52911620703c5 on campaignmonitor:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 96.532% when pulling 55f9a0c4d2240a2f5076586aee26b0b82f658a35 on tysonclugg:issue/26-timeout-api into 9fdcb0b68fc273f88ce2800a4be52911620703c5 on campaignmonitor:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 96.532% when pulling 55f9a0c4d2240a2f5076586aee26b0b82f658a35 on tysonclugg:issue/26-timeout-api into 9fdcb0b68fc273f88ce2800a4be52911620703c5 on campaignmonitor:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.01%) to 96.532% when pulling 55f9a0c4d2240a2f5076586aee26b0b82f658a35 on tysonclugg:issue/26-timeout-api into 9fdcb0b68fc273f88ce2800a4be52911620703c5 on campaignmonitor:master.