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

use requests library for raw_iter, to support custom http_session #229

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions datapackage/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import json
import warnings
import cchardet
import requests
from copy import deepcopy
from tableschema import Table, Storage
from six.moves.urllib.parse import urljoin
from six.moves.urllib.request import Request, urlopen
from six.moves.urllib.request import urlopen
from .profile import Profile
from . import exceptions
from . import helpers
Expand Down Expand Up @@ -206,8 +207,13 @@ def raw_iter(self, stream=False):
if self.multipart:
filelike = _MultipartSource(self.source, remote=self.remote)
elif self.remote:
request = Request(self.source, headers=config.HTTP_HEADERS)
filelike = urlopen(request)
if self.__table_options.get('http_session'):
http_session = self.__table_options['http_session']
else:
http_session = requests.Session()
http_session.headers = config.HTTP_HEADERS
res = http_session.get(self.source, stream=True)
filelike = res.raw
else:
filelike = io.open(self.source, 'rb')

Expand Down