Cannot open jpg images with PIL or open()

2024/11/15 20:07:45

I am testing to save ImageField in Django, but for some reason all the *.jpg files I've tried don't work while the one png I had works. Using django shell in WSL VCode terminal.

python 3.7

django 3.0

pillow 7.1.2

If I do with open():

# this has no error
f = open('loko.jpg', 'rb')#if I do 
f.read()  # it shows only b'', like its empty# this saves the field but the image is 0 bytes and cannot be open
object.image.save('name', File(f))

If I do with PIL:

from PIL import Image# this shows error
# PIL.UnidentifiedImageError: cannot identify image file 'loko.jpg'
img = Image.open('loko.jpg')

With the .png image I've tried, both methods work great.

What could be the problem?

Answer

Solution was to update the python-pillow package.

Now it works.

https://en.xdnf.cn/q/119276.html

Related Q&A

how to delete tensorflow model before retraining

I cant retrain my image classifier with new images, I get the following error:AssertionError: Export directory already exists. Please specify a different export directory: /tmp/saved_models/1/How do I …

Use beautifulsoup to scrape a table within a webpage?

I am scraping a county website that posts emergency calls and their locations. I have found success webscraping basic elements, but am having trouble scraping the rows of the table. (Here is an example…

Encrypt folder or zip file using python

So I am trying to encrypt a directory using python and Im not sure what the best way to do that is. I am easily able to turn the folder into a zip file, but from there I have tried looking up how to en…

Use Python Element Tree to parse xml in ASCII text file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Time series plot showing unique occurrences per day

I have a dataframe, where I would like to make a time series plot with three different lines that each show the daily occurrences (the number of rows per day) for each of the values in another column. …

Problem accessing indexed results two stage stochastic programming Pyomo

When running a stochastic programming problem in Pyomo, the resulting solution works only when running 10 precisely the same scenarios but the results remain zero when running different scenarios. I ai…

Pandas python + format for values

This is the code:import pandas as pd from pandas import Series, DataFrame import numpy as np import matplotlib.pyplot as pltdf.head(3).style.format({Budget: "€ {:,.0f}"}) Year …

Is there any implementation of deconvolution?

Some one may prefer to call it the transposed convolution, as introduced here. Im looking forward to an implementation of the transposed convolution, in Python or C/C++. Thank you all for helping me!

discord.py How to check if user is on server?

I need to check if the user is on the server. Please help me

Inserting variable stored data into SQLite3 - Python 3

I have been reading information on how to insert data into a database using data stored in a variable. I have not been able to get my data to load to my database and I am not sure why.The program is w…