Comments (2)
You are reusing a readable stream that has been already read for the first 10 bytes.
The requests
package response.content
implements an iterable stream that flushes the internal buffer once data is pulled from it (in this case via iterable).
This should work instead:
import filetype
import requests
url = "https://45.img.avito.st/image/1/lCc6lra4OM5MM8rIHszqVLE1PsiYNTjI_1Y-woo1OM7K"
r = requests.get(url)
head = r.content[:10]
filetype.guess(head).kind
filetype.guess(head).kind
from filetype.py.
I know this is old, but I am in the same situation. This is what I have...
img_stream = requests.get(url, stream=True)
head = img_stream.content[:10] # this has binary and JFIF for my test file
file_info = filetype.guess(head).kind
and I get the same error as OP. With your example you left out Stream, but I don't want to download the file locally. I am saving it to S3 directly.
from filetype.py.
Related Issues (20)
- PDF file won't begin with '%PDF-X.Y'
- tests/fixtures/sample.zst is missing from the repository HOT 1
- "1.0.13" --> "1.1.0" regression. `filetype.guess` stopped working with output from `read(file_path, "rb")` HOT 1
- xlsx file guess error HOT 2
- Does not recognize mp3 type
- Support `io.BytesIO` as input HOT 7
- xls and xlsx guessed as zip HOT 5
- One type of mp4 is not supported (compatibility with libmagic) HOT 1
- audio/m4a files are matched as video/mp4
- The csv file is not recognized. Can it be supported HOT 1
- Whether the detection of the other audio formats can be supported?
- Animated AVIFs aren't recognized
- MS Word misidentified as MS Excel HOT 1
- Font mimetypes are outdated HOT 4
- Access to types module blocked by assignment
- Incorrect documentation for functions accepting "bytes"
- support python 3.10+
- Add support to txt file HOT 2
- Empty docx file can't seem to get file type
- Docx detected as Zip due to trash files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filetype.py.