Add timeouts to all telnet read_until's
This commit is contained in:
		
							
								
								
									
										22
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								main.py
									
									
									
									
									
								
							| @@ -27,13 +27,13 @@ async def delete_message(mid): | ||||
|     logging.info('Deleting message ID: %s...', mid) | ||||
|  | ||||
|     with Telnet('192.168.168.1', 23, timeout=10) as tn: | ||||
|         tn.read_until(b'login: ') | ||||
|         tn.read_until(b'login: ', timeout=4) | ||||
|  | ||||
|         tn.write(b'admin\n') | ||||
|         tn.read_until(b'Password: ') | ||||
|         tn.read_until(b'Password: ', timeout=4) | ||||
|  | ||||
|         tn.write(settings.ROUTER_PASS.encode() + b'\n') | ||||
|         tn.read_until(b'UserDevice> ') | ||||
|         tn.read_until(b'UserDevice> ', timeout=4) | ||||
|  | ||||
|         command = 'AT+CMGD={}\r\n'.format(str(mid)) | ||||
|  | ||||
| @@ -51,16 +51,16 @@ async def delete_message(mid): | ||||
|  | ||||
|  | ||||
| async def send_message(number, text): | ||||
|     logging.info('Sending to %s message: %s...', number, text) | ||||
|     logging.info('Sending to %s message: %s', number, text) | ||||
|  | ||||
|     with Telnet('192.168.168.1', 23, timeout=10) as tn: | ||||
|         tn.read_until(b'login: ') | ||||
|         tn.read_until(b'login: ', timeout=4) | ||||
|  | ||||
|         tn.write(b'admin\n') | ||||
|         tn.read_until(b'Password: ') | ||||
|         tn.read_until(b'Password: ', timeout=4) | ||||
|  | ||||
|         tn.write(settings.ROUTER_PASS.encode() + b'\n') | ||||
|         tn.read_until(b'UserDevice> ') | ||||
|         tn.read_until(b'UserDevice> ', timeout=4) | ||||
|  | ||||
|         command = 'AT+CMGS={}\r\n'.format(str(number)) | ||||
|  | ||||
| @@ -88,13 +88,13 @@ async def get_messages(): | ||||
|     # handles no messages (empty response) fine | ||||
|  | ||||
|     with Telnet('192.168.168.1', 23, timeout=10) as tn: | ||||
|         tn.read_until(b'login: ') | ||||
|         tn.read_until(b'login: ', timeout=4) | ||||
|  | ||||
|         tn.write(b'admin\n') | ||||
|         tn.read_until(b'Password: ') | ||||
|         tn.read_until(b'Password: ', timeout=4) | ||||
|  | ||||
|         tn.write(settings.ROUTER_PASS.encode() + b'\n') | ||||
|         tn.read_until(b'UserDevice> ') | ||||
|         tn.read_until(b'UserDevice> ', timeout=4) | ||||
|  | ||||
|         tn.write(b'AT+CMGL\r\n') | ||||
|         res = tn.read_until(b'UserDevice> ', timeout=4).decode() | ||||
| @@ -180,7 +180,7 @@ async def send(event): | ||||
|     res = await send_message(number, message) | ||||
|  | ||||
|     if res: | ||||
|         await event.reply('Ok.') | ||||
|         await event.reply('ok') | ||||
|     else: | ||||
|         await event.reply('Error sending SMS.') | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user