i am using a 32 bit python to run it on my win 8 machine, when i run the program skype is responding with a message (seen in the top bar) : "Another application (python.exe) is attempting to access Skype , but we are unable to respond. Please try to restart the application"
Code:
import Skype4Py
import socket
import codecs
import sys
#setup
#sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#server_address = ('127.0.0.1', 65205)
#print 'starting up on '+ str(server_address[1])
#sock.bind(server_address)
#sock.listen(1)
#enableling different languages
UTF8Writer = codecs.getwriter('utf8')
sys.stdout = UTF8Writer(sys.stdout)
#skype setup
skype =Skype4Py.Skype()
availFriends = []
skype.Attach()
#block mode
def mstat(Message,status):
if(status == Skype4Py.cmsReceived ):#act on receive
Message.MarkAsSeen()
print Message.Body
skype.SendMessage(Message.Sender.Handle,"Did you send me :\n"+Message.Body+"\n good , Stop messaging me!")
def GetAllOnlinePeople():
availFriends = []
badStatusCodes = ['UNKNOWN', 'OFFLINE', 'DND', 'LOGGEDOUT']
for f in skype.Friends:
if not f.OnlineStatus in badStatusCodes:
availFriends.append(f)
###########################################3
#connection, client_address = sock.accept()
#print 'connection from'+ str(client_address[0])
# Receive the data in small chunks and retransmit it
#data = connection.recv(128)
#if data== 'bmode':
skype.OnMessageStatus = mstat
while(1==1):
i='p'
Not sure that this would help, but recently I've seen the similar message form skype while I was trying to start sevabot from Windows PowerShell.
Pls, see the screenshot below:
As soon as I launched it from windows cmd, that alert has gone.
My Skype version is 7.16.85.102 and Skype4Py version is 1.0.35.
Hope that helps.
Related
I have an ESP32 board which sends data via bluetooth. I can receive data on PC using this python code:
from bluetooth import *
import sys
def input_and_send():
while True:
data = input()
if len(data) == 0: break
sock.send(data)
sock.send("\n")
def rx_and_echo():
sock.send("\nsend anything\n")
while True:
data = sock.recv(buf_size)
if data:
print(data.decode('utf-8'))
sock.send(data)
addr = "XX:XX:XX:XX:XX:XX"
service_matches = find_service( address = addr )
buf_size = 1024
if len(service_matches) == 0:
print("couldn't find the SampleServer service =(")
sys.exit(0)
for s in range(len(service_matches)):
print("\nservice_matches: [" + str(s) + "]:")
print(service_matches[s])
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
port = 1
print("connecting to \"%s\" on %s, port %s" % (name, host, port))
sock = BluetoothSocket(RFCOMM)
sock.connect((host, port))
print("connected")
# input_and_send()
rx_and_echo()
sock.close()
Data.append(data.decode('utf-8'))
Now, I want to get data on android phone. I wrote a python program using kivy, but bluetooth package does not work on android. I tried bleak and jnius packages, but they did not work. Is there another packages which can use bluetooth of phone properly? I see, some persons advise using jnius package for android, but I could not get data using "BluetoothReceive" function.
Any help is appreciated.
I understood how to receive data using python on android. I used jnius package, and tried to look errors using this code on android phone.
I found theBufferReader should be used instead of getInputStream(), and readLine() instead of readline(). You can receive data using the below code:
from jnius import autoclass
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
UUID = autoclass('java.util.UUID')
BufferReader = autoclass('java.io.BufferedReader')
InputStream = autoclass('java.io.InputStreamReader')
paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
socket = None
for device in paired_devices:
if device.getName() == 'ESP32':
socket = device.createRfcommSocketToServiceRecord(
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
recv_stream = BufferReader(InputStream(socket.getInputStream()))
break
socket.connect()
Serial_Data = recv_stream.readLine()
Add this bluetooth permision to your buildozer.spec file.
android.permissions = BLUETOOTH, BLUETOOTH_ADMIN, ACCESS_FINE_LOCATION
Since jnius package does not work on PC (Windows or Linux), I hope there be another way to debug the python code directly, without making application and testing it on android phone.
Hope you´re fine! and really hope you can help me on this.
I have 2 ESP32 and 1 raspberry. Each ESP32 has a button, when I press any of the buttons a message must be sent over bluetooth of each ESP32.
ESP32_1 MESSAGE: "1L 100 100 200 200"
ESP32_2 MESSAGE: "2R 100 100 200 200"
I could connect ESP32 and raspberry over bluetooth successfully using the following command in 2 different terminals:
sudo rfcomm connect 1 XX:XX:XX:XX:XX (MAC1)
sudo rfcomm connect 2 XX:XX:XX:XX:XX (MAC2)
What I need is that if I press button_1 of ESP32_1 the message 1 must be received in raspberry. Otherwise, if I press button_2 of ESP32_2 the message 2 must be received and print in the raspberry.
The issue is that when I press button_2 dont send nothing and when I press button_1 after that, is sending information of button_2 + button_1, it seems like the port is waiting for receive the info in the other one.
Here my Python code for Raspberry:
#! /usr/bin/python
import serial
import time
Incoming_Data1 = ""
Incoming_Data2 = ""
bluetoothSerial1 = serial.Serial("/dev/rfcomm1", baudrate =115200) #Connecting to source 1
bluetoothSerial2 = serial.Serial("/dev/rfcomm2", baudrate =115200) #Connecting to source 1
print("Bluetooth Connected GBF")
def Flush_all():
bluetoothSerial1.flush()
bluetoothSerial2.flush()
while 1:
try:
Flush_all()
Incoming_Data1 = bluetoothSerial1.readline()
print(Incoming_Data1)
Flush_all()
except:
Flush_all()
try:
Flush_all()
Incoming_Data2 = bluetoothSerial2.readline()
print(Incoming_Data2)
Flush_all()
except:
Flush_all()
Thanks in advance!
It would be best to avoid using rfcomm as it was deprecated back in 2017
As outlined in http://blog.kevindoran.co/bluetooth-programming-with-python-3/, a Serial Port Profile (SPP) Bluetooth client connection can be done with Python3 standard socket library (after doing the pairing in bluetoothctl).
The example in Kevin's blog could be extended to work for connecting to two devices. Maybe something like:
import socket
serverMACAddress1 = 'XX:XX:XX:XX:XX:XX'
serverMACAddress2 = 'XX:XX:XX:XX:XX:XX'
port = 1 # Needs to match value used on the device you are connecting to
SIZE = 1024
s1 = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
s2 = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
s1.connect((serverMACAddress1, port))
s2.connect((serverMACAddress2, port))
while True:
data = s1.recv(size)
if data:
print(data)
data = s2.recv(size)
if data:
print(data)
s1.close()
s2.close()
There is also the Bluedot library that helps to abstract some of the detail away:
https://www.stuffaboutcode.com/2017/07/python-bluetooth-rfcomm-client-server.html
I'm trying to send a file from my laptop(win10) to my mobile(android) over bluetooth. I followed this answer and I'm doing the same with python 3.6
I'm using PyOBEX Python 3 Package and this is what I've tried.
import sys
from PyOBEX.client import Client
from bluetooth import *
addr = '60:7E:DD:A7:42:43'
print("Searching for OBEX service on {}".format(addr))
services = find_service(address=addr, name=b'OBEX Object Push\x00')
if len(services) == 0:
sys.exit()
first_match = services[0]
port = first_match["port"]
client = Client(addr, port)
client.connect()
client.put("test.txt", "Hello world\n")
client.disconnect()
When I run this, the device is discovered but it doesn't establish a connection or send files. This is the error it gives
I tried messing around with the PyOBEX package by changing the type of data returned by socket_.recv to str but it gives me another error,
I'm stuck and I have never worked with bluetooth or sockets before. Any help is appreciated
Using SQL 2016 & Python 3.7
I currently have two python programs:
A server that receives input from a socket and returns output
A client that sends a prompt to the socket, reads the response and then outputs.
I then have a script in SQL Server that uses xp_cmdshell to run the client and read the results. I'd like to be able to remove the client from the process by using SQL Server to directly access the socket. Unfortunately since you can access SQL Server as a socket, my searches are receiving a high level of noise and not giving me the results I need.
If I upgrade to SQL2017 I can use the internal python option to run the client locally, however upgrading will not be an option for some of our cients and I need a one size fits all solution.
Example Server: SimpleSocket.py:
import socket
from _thread import *
HEADER_LENGTH = 10
def threaded(local_client_socket):
command_header = local_client_socket.recv(HEADER_LENGTH)
command_length = int(command_header.decode("utf-8"))
command = local_client_socket.recv(command_length).decode("utf-8")
if not command:
print('Connection closed by client')
print("Received from client:", command)
reply = f"You sent me '{command}' This is my reply.".encode("utf-8")
reply_header = str(len(reply)).zfill(HEADER_LENGTH).encode("utf-8")
local_client_socket.send(reply_header + reply)
local_client_socket.close()
def open_sockets():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 9878))
print("Socket bound to port", 9878)
s.listen(16)
print("Socket is listening")
print("-" * 80)
while True:
client_socket, address = s.accept()
print('Connected to :', address[0], ':', address[1])
start_new_thread(threaded, (client_socket,))
if __name__ == '__main__':
open_sockets()
Example Client: SimpleClient.py
import socket
import sys
HEADER_LENGTH = 10
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("127.0.0.1", 9878))
command = "Text I'm sending to server".encode("utf-8")
command_header = str(len(command)).zfill(HEADER_LENGTH).encode("utf-8")
client_socket.send(command_header + command)
reply_header = client_socket.recv(HEADER_LENGTH)
if not len(reply_header):
print("Done")
sys.exit()
reply_length = int(reply_header.decode("utf-8"))
reply = client_socket.recv(reply_length).decode(("utf-8"))
print("Reply from server:", reply)
client_socket.close()
Example SQL Call:
DECLARE #Python_Location NVARCHAR(255) = N'c:\ProgramData\Anaconda3\envs\Search\python.exe'
, #Python_Script NVARCHAR(255) = N'c:\PythonScripts\Search\SimpleClient.py'
, #Command NVARCHAR(255)
SET #Command = N'"' + #Python_Location + N' ' + #Python_Script + '"'
PRINT #Command;
EXECUTE AS USER = 'cmdshell';
EXEC xp_cmdshell #stmt = #Command;
REVERT;
I have used OLE Automation in the past to pull data from a webservice, so was wondering if that may be an option. It's not really an area I know well and my searches haven't turned up anything relevant.
I'd be interested in knowing any options available to me, and all offerings gratefully received. Even if you don't have a full answer, any help may send me in a good direction, or help me structure my search queries to be more relevant. I may even be able to adjust the python code to output the result set to a different format if there's an efficient option.
Many thanks.
I am making a chat using the socket library in python, it works, only half way though, when you netcat onto what I am using as a channel I am able to send messages and the other terminal is able to receive them, but, when that terminal sends a message (typing text, then hit enter) I do not receive it through the python script. So I ran it raw in the following way:
python shell:
import socket
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(("127.0.0.1",8000)
sock.listen(2)
(client, (ip,port))=sock.accept()
Terminal:
nc 127.0.0.1 8000
This worked and to send or receive in the python shell all I had to do was type: sock.send("message") or sock.recv(2012)
Here is My code:
#!/bin/python
import socket
import subprocess
from subprocess import Popen, PIPE
import time
class color:
r = '\033[31m'
g = '\033[32m'
d = '\033[0m'
b = '\033[94m'
p = '\033[35m'
def clear():
print('\n' * 100)
chat_clients = []
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clear()
def chatting_on_serverr():
(client, (ip, port))=sock.accept()
def chatting_on_server():
message = raw_input("Send Message: ")
client.send(message + '\n')
client.recv(2012)
chatting_on_server()
chatting_on_server()
def make_channel():
print color.b + '[+] '+color.d+'Welcome to the chat server'+color.b+' [+]'
host = raw_input("Channel Name: ")
port = input("Channel Access Key: ")
clear()
print color.p + "[info] "+color.b+"Making %s" % host
time.sleep(1)
sock.bind((host,port))
sock.listen(3)
print color.g + "[+] "+color.d+"Channel Made"+color.g+" [+]"+color.d
print("[info]: Waiting for people to join your channel...")
global chatting_on_serverr
global chatting_on_server
chatting_on_serverr()
clear()
make_channel()
I cannot reproduce this on my machine because of network limitations but I recommend you to look at this tutorial of a Python chat client and server. It will explain a lot about sockets and networking.
Beside that you shouldn't define globals with the same name as functions in your code. It might override their declaration. Another thing is the function inside the function. You can write that function like that:
def chatting_on_server():
client, (ip, port) = sock.accept()
while True:
message = raw_input("Send Message: ")
client.send(message + '\n')
client.recv(2012)
And you will get the same functionality. Also, you risk yourself with a stack overflow error because chatting_on_server calls itself forever.
Good luck!
All that was needed to be done is to print the output of the .recv function
x = client.recv(2020)
print(x)