@@ -108,6 +108,17 @@ def __init__(self, instance_id, secret_key, endpoint=None):
108
108
self .secret_key = secret_key
109
109
self ._endpoint = endpoint
110
110
111
+ session = requests .Session ()
112
+ # We've had multiple support requests about this library not working
113
+ # on PythonAnywhere (a popular python deployment platform)
114
+ # They require that proxy servers be loaded from the environment when
115
+ # making requests (on their free plan).
116
+ # This reintroduces the proxy support that is the default in requests
117
+ # anyway.
118
+ session .proxies = _get_proxies_from_env ()
119
+ self .session = session
120
+
121
+
111
122
@property
112
123
def endpoint (self ):
113
124
"""Property method to calculate the correct Pusher API host"""
@@ -124,15 +135,6 @@ def _make_request(self, method, path, path_params, body=None):
124
135
path = path .format (** path_params )
125
136
url = _make_url (scheme = 'https' , host = self .endpoint , path = path )
126
137
127
- 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
-
136
138
request = requests .Request (
137
139
method ,
138
140
url ,
@@ -146,7 +148,7 @@ def _make_request(self, method, path, path_params, body=None):
146
148
},
147
149
)
148
150
149
- response = session .send (request .prepare ())
151
+ response = self . session .send (request .prepare ())
150
152
151
153
if response .status_code != 200 :
152
154
try :
0 commit comments