Skip to content

Commit cf391b3

Browse files
alecdwmMaskRay
authored andcommitted
replaced mimetypes with libmagic to prevent 'TypeError: must be str, not NoneType'
1 parent 6e59c0b commit cf391b3

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ telegramircd uses [telethon-sync](https://github.com/LonamiWebs/Telethon) to com
1010

1111
- `git clone https://github.com/MaskRay/telegramircd && cd telegramircd`
1212
- python >= 3.5
13+
- libmagic
1314
- `pip3 install -r requirements.txt`
1415

1516
Create a Telegram App.

README.zhs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ telegramircd使用[Telethon](https://github.com/LonamiWebs/Telethon)和Telegram
88

99
- `git clone https://github.com/MaskRay/telegramircd && cd telegramircd`
1010
- python >= 3.5
11+
- libmagic
1112
- `pip3 install -r requirements.txt`
1213

1314
创建一个Telegram App。

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
aiohttp
2+
python-magic
23
ipdb
34
ipython
45
configargparse

telegramircd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import telethon.tl.functions.contacts
1515
import telethon.tl.functions.messages
1616

17-
import aiohttp.web, asyncio, base64, inspect, json, logging.handlers, mimetypes, os, pprint, random, re, \
17+
import aiohttp.web, asyncio, base64, inspect, json, logging.handlers, magic, os, pprint, random, re, \
1818
shlex, signal, socket, ssl, string, sys, tempfile, time, traceback, uuid, weakref
1919

2020
logger = logging.getLogger('telegramircd')
@@ -95,7 +95,7 @@ async def handle_media(self, typ, request):
9595
except:
9696
pass
9797
if mime is None:
98-
mime = mimetypes.guess_type(filename)[0]
98+
mime = magic.from_file(filename, mime=True)
9999
return aiohttp.web.Response(body=f.read(), headers={'Content-Type': mime})
100100
except Exception as ex:
101101
return aiohttp.web.Response(status=500, text=str(ex))

0 commit comments

Comments
 (0)