mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Report errors to pwrtelegram.xyz by default
This commit is contained in:
parent
2517b9787d
commit
00b5b5021b
|
@ -263,3 +263,17 @@ Once this is done, pass the proxy settings to the ``TelegramClient`` constructor
|
|||
|
||||
The ``proxy=`` argument should be a tuple, a list or a dict, consisting of parameters described
|
||||
`here <https://github.com/Anorov/PySocks#usage-1>`_.
|
||||
|
||||
API status
|
||||
----------
|
||||
|
||||
In an attempt to help everyone who works with the Telegram API, Telethon
|
||||
will by default report all Remote Procedure Call errors to
|
||||
`PWRTelegram <https://pwrtelegram.xyz/>`_, a public database anyone
|
||||
can query, made by `Daniil <https://github.com/danog>`_. All the information
|
||||
sent is a ``GET`` request with the error code, error message and method used.
|
||||
|
||||
If you still would like to opt out, simply set
|
||||
``client.session.report_errors = False`` to disable this feature. However
|
||||
Daniil would really thank you if you helped him (and everyone) by keeping
|
||||
it on!
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import urllib.request
|
||||
import re
|
||||
|
||||
from .common import (
|
||||
|
@ -16,7 +17,22 @@ from .rpc_errors_401 import *
|
|||
from .rpc_errors_420 import *
|
||||
|
||||
|
||||
def rpc_message_to_error(code, message):
|
||||
def rpc_message_to_error(code, message, report_method=None):
|
||||
if report_method is not None:
|
||||
try:
|
||||
# Ensure it's signed
|
||||
report_method = int.from_bytes(
|
||||
report_method.to_bytes(4, 'big'), 'big', signed=True
|
||||
)
|
||||
url = urllib.request.urlopen(
|
||||
'https://rpc.pwrtelegram.xyz?code={}&error={}&method={}'
|
||||
.format(code, message, report_method)
|
||||
)
|
||||
url.read()
|
||||
url.close()
|
||||
except:
|
||||
"We really don't want to crash when just reporting an error"
|
||||
|
||||
errors = {
|
||||
303: rpc_errors_303_all,
|
||||
400: rpc_errors_400_all,
|
||||
|
|
|
@ -344,8 +344,15 @@ class MtProtoSender:
|
|||
request = None
|
||||
|
||||
if inner_code == 0x2144ca19: # RPC Error
|
||||
error = rpc_message_to_error(
|
||||
reader.read_int(), reader.tgread_string())
|
||||
if self.session.report_errors and request:
|
||||
error = rpc_message_to_error(
|
||||
reader.read_int(), reader.tgread_string(),
|
||||
report_method=type(request).constructor_id
|
||||
)
|
||||
else:
|
||||
error = rpc_message_to_error(
|
||||
reader.read_int(), reader.tgread_string()
|
||||
)
|
||||
|
||||
# Acknowledge that we received the error
|
||||
self._need_confirmation.append(request_id)
|
||||
|
|
|
@ -109,6 +109,7 @@ class JsonSession:
|
|||
self.lang_code = session.lang_code
|
||||
self.system_lang_code = session.system_lang_code
|
||||
self.lang_pack = session.lang_pack
|
||||
self.report_errors = session.report_errors
|
||||
|
||||
else: # str / None
|
||||
self.session_user_id = session_user_id
|
||||
|
@ -120,6 +121,7 @@ class JsonSession:
|
|||
self.lang_code = 'en'
|
||||
self.system_lang_code = self.lang_code
|
||||
self.lang_pack = ''
|
||||
self.report_errors = True
|
||||
|
||||
# Cross-thread safety
|
||||
self._lock = Lock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user