Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

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

## [1.1.0] - 2019-02-06
### Added
Expand Down
16 changes: 16 additions & 0 deletions pusher_push_notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import datetime
import json
import os
import re
import time
import warnings
Expand Down Expand Up @@ -76,6 +77,13 @@ def _make_url(scheme, host, path):
])


def _get_proxies_from_env():
return {
'http': os.environ.get('HTTP_PROXY') or os.environ.get('http_proxy'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's case sensitive? :o

'https': os.environ.get('HTTPS_PROXY') or os.environ.get('https_proxy'),
}


class PushNotifications(object):
"""Pusher Push Notifications API client
This client class can be used to publish notifications to the Pusher
Expand Down Expand Up @@ -117,6 +125,14 @@ def _make_request(self, method, path, path_params, body=None):
url = _make_url(scheme='https', host=self.endpoint, path=path)

session = requests.Session()
# We've had multiple support requests about this library not working
# on PythonAnywhere (a popular python deployment platform)
# They require that proxy servers be loaded from the environment when
# making requests (on their free plan).
# This reintroduces the proxy support that is the default in requests
# anyway.
session.proxies = _get_proxies_from_env()

request = requests.Request(
method,
url,
Expand Down