error in server side of pygame video streaming - python-2.7

i am new to pygame and trying to stream video over pygame.
my client side is working fine but in sender side i get error and sender and client are not connecting.
my sender code is:
import socket,os
from PIL import *
import pygame,sys
import pygame.camera
from pygame.locals import *
#Create server:
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("10.3.100.207",5000))
server.listen(5)
#Start Pygame
pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode((320,240))
cam = pygame.camera.Camera("/dev/video0",(320,240),"RGB")
cam.start()
#Send data
while True:
s,add = server.accept()
print "Connected from",add
image = cam.get_image()
screen.blit(image,(0,0))
data = cam.get_raw()
s.sendall(data)
pygame.display.update()
#Interupt
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
but when i run this code i get this following error
siplab#siplab-OptiPlex-9020:~$ python tut1.py
Traceback (most recent call last):
File "tut1.py", line 9, in <module>
server.bind(("10.3.100.207",5000))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address

Related

Not sure why my email script is not sending an email

It was working but after updating my Raspberry Pi, my python script to send an email is not sending and I'm not sure why. It seems to just hang without throwing any error messages and I have to Ctrl+C to stop it every time, otherwise it'll just sit there indefinitely.
Here is my code...
import smtplib, datetime
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
email_send = [sender email]
email_receive = [my email]
password = [password]
subject = 'Test Subject'
#sYMD = datetime.date.today().strftime('%y%m%d')
#lpath = 'C:/Path/to/files/'
files = ['log1.txt', 'log2.txt']
msg = MIMEMultipart()
msg['From'] = email_send
msg['To'] = email_receive
msg['Subject'] = subject
body = """\
Test Message."""
msg.attach(MIMEText(body, 'plain'))
#filename = x.strftime("%y%m%d")+'_log.txt'
for file in files:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(file, "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % file)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.office365.com', 587)
server.starttls()
server.login(email_send, password)
server.sendmail(email_send, email_receive, text)
server.quit()
Here is what its doing when I run the script...
pi#raspberrypi: python send_email.py
^CTraceback (most recent call last):
File "send_email.py", line 36, in <module>
server = smtplib.SMTP('smtp.office365.com', 587)
File "/usr/lib/python2.7/smtplib.py", line 265, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 317, in connect
(code, msg) = self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 361, in getreply
line = self.file.readline(_MAXLINE + 1)
File "/usr/lib/python2.7/socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
Thanks for any help you can give.
Hmm sounds like the connection is timing out. Is it possible the client is unable to connect to the specified server and port? Try connecting directly with nc or telnet to confirm.
You can also pass a timeout value in seconds to the SMTP call:
server = smtplib.SMTP('smtp.office365.com', 587, timeout=5)

Google App Engine Cron Job failing with following error

Same code deployed on development system works fine but once deployed to production fails with following error:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named urlhandlers
Following is the URL handler code:
import traceback
import datetime
from google.appengine.api import taskqueue
import re
import webapp2
from utilities.logger import logThis, AEL_LEVEL_INFO, AEL_LEVEL_CRITICAL
from constants.constants import GAET_MASTERTASK_NAME, GAEQ_FOR_MASTERTASK
import sys
class QueueAMasterTask(webapp2.RequestHandler):
def get(self):
try:
dt =datetime.datetime.now()
logThis(AEL_LEVEL_INFO, 'Master Task added to its Q at[%s]' %(dt))
task_name = GAET_MASTERTASK_NAME + str(datetime.datetime.now())
task_name = re.sub('[^a-zA-Z0-9_-]', '_', task_name)
taskqueue.add(queue_name=GAEQ_FOR_MASTERTASK,name=task_name)
logThis(AEL_LEVEL_INFO, "OK-MASTER TASK ADD")
except taskqueue.DuplicateTaskNameError:
logThis(AEL_LEVEL_CRITICAL, "EXCEPTION on QueueAMasterTask-" + traceback.format_exc())
except:
logThis(AEL_LEVEL_CRITICAL, "EXP on QueueAMasterTask-" + traceback.format_exc())
app = webapp2.WSGIApplication([('/QueueAMasterTask', QueueAMasterTask)
], debug=True)
Cron job error log

Paramiko start_server Not Working

I created a program for accessing a server via Paramiko and sockets.
#make imports
from socket import *
from datetime import datetime
from pickle import load, dump
from Crypto.Hash import SHA256
from subprocess import check_output as exeCMD
from sqlite3 import connect as SQLconnect
import paramiko, sys, threading, os
#get password from file
pasword = load(open("usrData/pswd.txt", "rb"))
#class for initiating server connection with client
class Server(paramiko.ServerInterface):
#initialize object
def __init__(self):
self.event = threading.Event()
#check password for user entry
def check_auth_password(self, username, password):
#where the error is
givenpswdHash = SHA256.new(password)
print(givenpswdHash.hexdigest())
if (username in unameList) and (givenpswdHash.hexdigest() == pasword):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
#what to execute in command line
def terminal(hostIP, hostPort, hostKeyPath, hostKeyPswd):
#create sockets before this etc...
#create server instance
server = Server()
#get server onto session
#where we call out server function
session.start_server(server=server)
#continue talking to client
When I launch the server, and get a client to connect to it, I get this error :
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
File "./terminalServer.py", line 212, in <module>
main()
File "./terminalServer.py", line 209, in main
terminal(ip, port, keyPath, keyPswd)
File "./terminalServer.py", line 142, in terminal
session.start_server(server=server)
File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 471, in start_server
raise e
ValueError: CTR mode needs counter parameter, not IV
It has something to do with the Crypto I added for password authentication. If anyone knows howto solve this issue, please
leave a comment. Thank you in advance.
All I had to do is replace all the alpha versions of pycrypto with the stable version. The current stable version (Sept. 1st 2015) for pycrypto is 2.6.1 and for paramiko it's 1.14.2.

error with Firefox Binary 'The browser appears to have exited'

I have problem with selenium and Firefox when i run my code below:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import urllib2,cookielib
import re
from pyvirtualdisplay import Display
import urllib
import urllib2
import httplib2
from os import system
display = Display(visible=0, size=(800, 600))
display.start()
name = 'test'
driver = webdriver.Firefox()
driver.get("http://example.com")
driver.switch_to_default_content()
inputElement = driver.find_element_by_name("name")
inputElement.send_keys(name)
inputElement.submit()
print "Please wait for 5s to get results.."
content = driver.page_source.encode("utf-8")
html = str(content)
soup = BeautifulSoup(html)
print soup
display.stop()
driver.close()
And i get this error:
Exception in thread command9:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "plugins/help_plugin.py", line 165, in handler_search
search_number_ar(type, source, parameters)
File "plugins/test.py", line 230, in search_test
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
my code running in vps and i use selenium-2.45.0 and firefox.x86_64-31.6.0.
I try alot of ways to solve my problem but nothing working with me.
I try to update selenium and i try to downgrade firefox and alot of solution.
Just to know when i run my code for the first time it work but when i run it again it show me the above error.
I hope someone help.

SIGHUP signal give exception with pika in python 2.7

I have a pika consumer
when i run it and sends SIGHUP signal, It gives me an exception
Consumertest.py
import signal
import traceback
import pika
from time import sleep
received_signal = False
def signal_handler(signal, frame):
global received_signal
received_signal = True
exit(1)
def sighup_handler(signal, frame):
print "sighup received"
signal.signal(signal.SIGHUP, sighup_handler)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
mq_server = "localhost"
mq_exchange = "my_exchange"
my_queue = "test_queue"
try:
mq_connection = pika.BlockingConnection(pika.ConnectionParameters(mq_server))
except:
exit(1)
mq_channel = mq_connection.channel()
mq_channel.exchange_declare(exchange=mq_exchange, durable=True)
mq_channel.queue_declare(queue=my_queue, durable=True)
mq_channel.queue_bind(my_queue, mq_exchange)
def callback(ch, method, properties, body):
try:
sleep(10)
ch.basic_reject(delivery_tag=method.delivery_tag)
except Exception as e:
traceback.print_exc() # region Message consumption
try:
print ' [*] Waiting for messages. To exit press CTRL+C'
mq_channel.basic_consume(callback, queue=my_queue)
mq_channel.start_consuming()
except Exception as e:
traceback.print_exc()
while True:
pass
exception:
[*] Waiting for messages. To exit press CTRL+C
sighup received
Traceback (most recent call last):
File "/run/media/bluto/04D0CF8ED0CF8500/Email_Projects/new_email_workers/testsigHup.py", line 47, in <module>
mq_channel.start_consuming()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 814, in start_consuming
self.connection.process_data_events()
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 168, in process_data_events
if self._handle_read():
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 271, in _handle_read
if self._read_poller.ready():
File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 54, in ready
events = self.poller.poll(self.poll_timeout)
error: (4, 'Interrupted system call')