use requests
This commit is contained in:
parent
893abbe9d5
commit
ef633b00b1
1 changed files with 2 additions and 1 deletions
|
@ -7,6 +7,7 @@ import socket
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
import requests
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
import ox.web.criterion
|
import ox.web.criterion
|
||||||
|
@ -85,7 +86,7 @@ class PosterCache(models.Model):
|
||||||
url = self.url.encode('utf-8')
|
url = self.url.encode('utf-8')
|
||||||
name = hashlib.sha1(url).hexdigest()
|
name = hashlib.sha1(url).hexdigest()
|
||||||
try:
|
try:
|
||||||
data = ox.net.read_url(url)
|
data = requests.get(url, headers=ox.net.DEFAULT_HEADERS).content
|
||||||
self.image.name = poster_path(self.url, os.path.basename(self.url))
|
self.image.name = poster_path(self.url, os.path.basename(self.url))
|
||||||
ox.makedirs(os.path.dirname(self.image.path))
|
ox.makedirs(os.path.dirname(self.image.path))
|
||||||
with open(self.image.path, 'wb') as f:
|
with open(self.image.path, 'wb') as f:
|
||||||
|
|
Loading…
Reference in a new issue