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

Update requests_csv.py #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions zipline/sources/requests_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,19 @@ def fetch_url(self, url):
if content_length > self.MAX_DOCUMENT_SIZE:
raise Exception('Document size too big.')
if chunk:
if isinstance(chunk, bytes):
if content_length == 0:
import codecs
if chunk[:3] == codecs.BOM_UTF8:
encoding = 'utf-8-sig'
elif chunk[:2] == codecs.BOM_UTF16_LE or chunk[:2] == codecs.BOM_UTF16_BE:
encoding = 'utf-16'
elif chunk[:4] == codecs.BOM_UTF32_LE or chunk[:4] == codecs.BOM_UTF32_BE:
encoding = 'utf-32'
else:
encoding = 'utf-8'
decoder = codecs.getincrementaldecoder(encoding)(errors='replace')
chunk = decoder.decode(chunk)
content_length += len(chunk)
yield chunk

Expand Down