Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sockets and Sendmail
#1
I have a socket client program that resends any received data to other connected clients.

I just added a function to send an email when certain data is received. I pass the data to the sendemail function and the email is sent.

However, when the program returns from the sendemail routine, I end up with a KeyError. If I comment out the actual sendmail() command, no KeyError is produced.

I can't figure out how these two things are related or what to do to fix it.

This all seems to work fine:

try:
  data = s.recv(64)
except socket.error, ex:
  print ex
if data:

# A readable client socket has data
    print '> ', data
    message_queues[s].put(data)

# Add output channel for response

if s not in outputs:
    outputs.append(s)
    update_html(data)
    checknewtrack(data)
    if (newtrack):
        sendemail()
But after coming back from the sendemail() function, it chokes on this code :

for s in writeable:
try:
    next_msg = message_queues[s].get_nowait() <---- KEYERROR HERE
except Queue.Empty:
    outputs.remove(s)
else:
    for t in connected_clients:
        t.send(next_msg)
Error:
Traceback (most recent call last): File "/home/user/bin/lora-gateway.py", line 192, in <module> do_work( True) File "/home/user/bin/lora-gateway.py", line 135, in do_work next_msg = message_queues[s].get_nowait() KeyError: <socket._socketobject object at 0x7f43a6617c20>
Any help would be appreciated.
Reply


Messages In This Thread
Sockets and Sendmail - by taintedsushi - Aug-27-2019, 12:44 PM
RE: Sockets and Sendmail - by taintedsushi - Aug-28-2019, 04:14 PM
RE: Sockets and Sendmail - by venquessa - Sep-02-2019, 12:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sockets interferring with USB ? epif18 0 2,706 Mar-19-2021, 07:45 PM
Last Post: epif18
  Just learning sockets etc... floatingshed 2 2,397 May-06-2020, 09:37 PM
Last Post: floatingshed
  Quick sockets question... ptrivino 2 2,294 Sep-26-2019, 08:51 PM
Last Post: ptrivino
  Script Conversion 2.7 to 3 (sockets) Pumpernickel 1 2,592 Apr-10-2019, 04:26 PM
Last Post: Pumpernickel
  What sort of things can I write to learn about sockets marienbad 2 2,756 Oct-16-2018, 04:02 PM
Last Post: buran
  unix domain sockets Skaperen 8 5,088 Sep-02-2018, 07:02 PM
Last Post: Skaperen
  file transfer with sockets sinister88 1 6,495 Nov-11-2017, 03:29 PM
Last Post: heiner55
  Trouble with sending raw sockets IronReign 2 4,261 Jun-01-2017, 08:26 AM
Last Post: camp0
  Silly Sockets Jarvis 2 4,267 Feb-20-2017, 01:43 PM
Last Post: Jarvis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020