Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Create Session object, over multiple requests.get #402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pyup/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import requests


def fetch_package(name, index_server=None):
def fetch_package(name, index_server=None,session=requests.Session()):
url = index_server + name if index_server else \
"https://pypi.org/pypi/{name}/json".format(name=name)
r = requests.get(url, timeout=3)
r = session.get(url, timeout=3)
if r.status_code != 200:
return None
json = r.json()
Expand Down
8 changes: 4 additions & 4 deletions pyup/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __init__(self, name, specs, line, lineno, extras, file_type):
self._package = None
self.file_type = file_type
self.pipfile = None

self.session = requests.Session()
self.hashCmp = (
self.key,
self.specs,
Expand Down Expand Up @@ -390,7 +390,7 @@ def get_latest_version_within_specs(specs, versions, prereleases=None):
@property
def package(self):
if not self._fetched_package:
self._package = fetch_package(self.name, self.index_server)
self._package = fetch_package(self.name, self.index_server,self.session)
self._fetched_package = True
return self._package

Expand Down Expand Up @@ -421,7 +421,7 @@ def changelog(self):
if self._changelog is None:
self._changelog = OrderedDict()
if settings.api_key:
r = requests.get(
r = self.session.get(
"https://pyup.io/api/v1/changelogs/{}/".format(self.key),
headers={"X-Api-Key": settings.api_key}
)
Expand Down Expand Up @@ -460,7 +460,7 @@ def full_name(self):
return self.name

def get_hashes(self, version):
r = requests.get('https://pypi.org/pypi/{name}/{version}/json'.format(
r = self.session.get('https://pypi.org/pypi/{name}/{version}/json'.format(
name=self.key,
version=version
))
Expand Down