️ Catching not images

Also got rid of the sleep
This commit is contained in:
2021-04-06 23:37:53 +03:00
parent 35a35ab9b1
commit d90b4a1b18
2 changed files with 6 additions and 5 deletions

View File

@@ -7,7 +7,8 @@ def detect(url):
response = requests.get(url)
try:
img = Image.open(io.BytesIO(response.content))
except OSError:
return ''
return pytesseract.image_to_string(img, lang='rus', timeout=30).lower()
string = pytesseract.image_to_string(img, lang='rus', timeout=30).lower()
except OSError: # Happens when whatever we get is not an image and cant be opened as such
string = ''
return string