Skip to content

Commit afacfbe

Browse files
Merge pull request #25 from pusher/support-proxy-env-vars
Add support for loading proxy config from the environment
2 parents dec67aa + 879c9b6 commit afacfbe

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Support for `HTTP_PROXY` environment variables. This should enable use of the
10+
SDK on the PythonAnywhere platform (see issue #24)
811

912
## [1.1.0] - 2019-02-06
1013
### Added

pusher_push_notifications/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import copy
44
import datetime
55
import json
6+
import os
67
import re
78
import time
89
import warnings
@@ -76,6 +77,13 @@ def _make_url(scheme, host, path):
7677
])
7778

7879

80+
def _get_proxies_from_env():
81+
return {
82+
'http': os.environ.get('HTTP_PROXY') or os.environ.get('http_proxy'),
83+
'https': os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy'),
84+
}
85+
86+
7987
class PushNotifications(object):
8088
"""Pusher Push Notifications API client
8189
This client class can be used to publish notifications to the Pusher
@@ -117,6 +125,14 @@ def _make_request(self, method, path, path_params, body=None):
117125
url = _make_url(scheme='https', host=self.endpoint, path=path)
118126

119127
session = requests.Session()
128+
# We've had multiple support requests about this library not working
129+
# on PythonAnywhere (a popular python deployment platform)
130+
# They require that proxy servers be loaded from the environment when
131+
# making requests (on their free plan).
132+
# This reintroduces the proxy support that is the default in requests
133+
# anyway.
134+
session.proxies = _get_proxies_from_env()
135+
120136
request = requests.Request(
121137
method,
122138
url,

0 commit comments

Comments
 (0)