So, I'm trying to use request.get to pull an image from the Internet and save it in a django database. These are the following code and the steps I took:
My model (just the right bit, not all)
class Pistol(models.Model):
gun_id = models.CharField(max_length=255)
manufacturer = models.CharField(max_length=255, blank=True)
model = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to='img/inventory', blank=True)
My code (I do this from the shell so that it seems disorganized)
import request
r = requests.get('http://media.server.theshootingwarehouse.com/small/2451.jpg')
item = Pistol(gun_id="1", price=400, image="1.jpg")
item.image.save('1.jpg',r.content)
And then I get the following error
AttributeError: 'bytes' object has no attribute 'read'
Note. I work in python3.
source
share