Skip to content

Commit b28d4b2

Browse files
Merge pull request #478 from scholarly-python-package/develop
Release v1.7.8
2 parents 599639a + 04658aa commit b28d4b2

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

.github/workflows/proxytests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name: Python package (with methods that need proxy)
55

66
on:
7-
pull_request:
7+
push:
88
branches: [main]
99

1010
jobs:
@@ -31,7 +31,6 @@ jobs:
3131
# uses: typilus/typilus-action@v0.9
3232
- name: Run unittests
3333
id: unittests
34-
if: ${{ github.event.pull_request.ready_for_review == true }}
3534
continue-on-error: true
3635
env:
3736
CONNECTION_METHOD: ${{ secrets.CONNECTION_METHOD }}

scholarly/_navigator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def use_proxy(self, pg1: ProxyGenerator, pg2: ProxyGenerator = None):
7474
self._session1 = self.pm1.get_session()
7575
self._session2 = self.pm2.get_session()
7676

77-
def _new_session(self, premium=True):
77+
def _new_session(self, premium=True, **kwargs):
7878
self.got_403 = False
7979
if premium:
80-
self._session1 = self.pm1._new_session()
80+
self._session1 = self.pm1._new_session(**kwargs)
8181
else:
82-
self._session2 = self.pm2._new_session()
82+
self._session2 = self.pm2._new_session(**kwargs)
8383

8484

8585
def _get_page(self, pagerequest: str, premium: bool = False) -> str:
@@ -112,7 +112,8 @@ def _get_page(self, pagerequest: str, premium: bool = False) -> str:
112112
w = random.uniform(1,2)
113113
time.sleep(w)
114114
resp = session.get(pagerequest, timeout=timeout)
115-
self.logger.debug("Session proxy config is {}".format(pm._proxies))
115+
if premium is False: # premium methods may contain sensitive information
116+
self.logger.debug("Session proxy config is {}".format(pm._proxies))
116117

117118
has_captcha = self._requests_has_captcha(resp.text)
118119

scholarly/_proxy_generator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ def _use_proxy(self, http: str, https: str = None) -> bool:
183183
:returns: whether or not the proxy was set up successfully
184184
:rtype: {bool}
185185
"""
186-
if https is None:
187-
https = http
188186
if http[:4] != "http":
189187
http = "http://" + http
190-
if https[:5] != "https":
188+
if https is None:
189+
https = http
190+
elif https[:5] != "https":
191191
https = "https://" + https
192192

193193
proxies = {'http://': http, 'https://': https}
@@ -205,7 +205,7 @@ def _use_proxy(self, http: str, https: str = None) -> bool:
205205

206206
if self._proxy_works:
207207
self._proxies = proxies
208-
self._new_session()
208+
self._new_session(proxies=proxies)
209209

210210
return self._proxy_works
211211

@@ -444,8 +444,9 @@ def _handle_captcha2(self, url):
444444

445445
return self._session
446446

447-
def _new_session(self):
447+
def _new_session(self, **kwargs):
448448
init_kwargs = {}
449+
init_kwargs.update(kwargs)
449450
proxies = {}
450451
if self._session:
451452
proxies = self._proxies
@@ -612,8 +613,9 @@ def ScraperAPI(self, API_KEY, country_code=None, premium=False, render=False):
612613
for _ in range(3):
613614
proxy_works = self._use_proxy(http=f'{prefix}:{API_KEY}@proxy-server.scraperapi.com:8001')
614615
if proxy_works:
616+
proxies = {'http://': f"http://scraperapi:{API_KEY}@proxy-server.scraperapi.com:8001",}
615617
self.logger.info("ScraperAPI proxy setup successfully")
616-
self._session.verify = False
618+
self._new_session(verify=False, proxies=proxies)
617619
return proxy_works
618620

619621
if (r["requestCount"] >= r["requestLimit"]):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='scholarly',
8-
version='1.7.7',
8+
version='1.7.8',
99
author='Steven A. Cholewiak, Panos Ipeirotis, Victor Silva, Arun Kannawadi',
1010
author_email='steven@cholewiak.com, panos@stern.nyu.edu, vsilva@ualberta.ca, arunkannawadi@astro.princeton.edu',
1111
description='Simple access to Google Scholar authors and citations',

0 commit comments

Comments
 (0)