urllib2 didn't handle chunked method
parent
e3a5a50f34
commit
4969994a87
|
@ -1,14 +1,14 @@
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
from PIL import ImageFile
|
from PIL import ImageFile
|
||||||
from sorl.thumbnail import get_thumbnail
|
from sorl.thumbnail import get_thumbnail
|
||||||
|
@ -1198,13 +1198,13 @@ class Ebook(models.Model):
|
||||||
return ebf.file
|
return ebf.file
|
||||||
|
|
||||||
def get_archive_ebf(self): # returns an ebf
|
def get_archive_ebf(self): # returns an ebf
|
||||||
if not self.ebook_files.filter(asking=False):
|
if not self.ebook_files.filter(asking=False).count():
|
||||||
if not self.provider in good_providers:
|
if not self.provider in good_providers:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
r = urllib2.urlopen(self.url)
|
r = requests.get(self.url)
|
||||||
try:
|
if r.status_code == 200:
|
||||||
self.filesize = int(r.info().getheaders("Content-Length")[0])
|
self.filesize = len(r.content)
|
||||||
if self.save:
|
if self.save:
|
||||||
self.filesize = self.filesize if self.filesize < 2147483647 else 2147483647 # largest safe positive integer
|
self.filesize = self.filesize if self.filesize < 2147483647 else 2147483647 # largest safe positive integer
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -1214,12 +1214,11 @@ class Ebook(models.Model):
|
||||||
format=self.format,
|
format=self.format,
|
||||||
source=self.url
|
source=self.url
|
||||||
)
|
)
|
||||||
ebf.file.save(path_for_file(ebf, None), ContentFile(r.read()))
|
ebf.file.save(path_for_file(ebf, None), ContentFile(r.content))
|
||||||
ebf.file.close()
|
ebf.file.close()
|
||||||
ebf.save()
|
ebf.save()
|
||||||
return ebf
|
return ebf
|
||||||
except IndexError:
|
else:
|
||||||
# response has no Content-Length header probably a bad link
|
|
||||||
logging.error('Bad link error: {}'.format(self.url))
|
logging.error('Bad link error: {}'.format(self.url))
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.error(u'could not open {}'.format(self.url))
|
logger.error(u'could not open {}'.format(self.url))
|
||||||
|
|
Loading…
Reference in New Issue