2017-02-26 7 views
1

コードには有効ではありません、次のとおりです:としてスローWindowsでのPython 3.5のBluetoothコンテキスト。要求されたアドレスは、そのコンテキスト

from bluetooth import * 
import sys 

if sys.version < '3': 
    input = raw_input 

addr = None 

if len(sys.argv) < 2: 
    print("no device specified. Searching all nearby bluetooth devices for") 
    print("the SampleServer service") 
else: 
    addr = sys.argv[1] 
    print("Searching for SampleServer on %s" % addr) 

# search for the SampleServer service 
addr = "CC:79:4A:4B:35:85" 
service_matches = find_service(address = addr) 

if len(service_matches) == 0: 
    print("couldn't find the SampleServer service =(") 
    sys.exit(0) 

first_match = service_matches[0] 
port = first_match["port"] 
name = first_match["name"] 
host = first_match["host"] 

print("connecting to \"%s\" at Address - %s on Port %d" % (name, host, port)) 

# Create the client socket 
sock=BluetoothSocket(RFCOMM) 
sock.connect((host, port)) 

print("connected. type stuff") 
while True: 
    data = input() 
    if len(data) == 0: break 
    sock.send(data) 

sock.close() 

実行時エラーは、次のとおりです。

no device specified. Searching all nearby bluetooth devices for 
the SampleServer service 
connecting to "None" at Address - CC:79:4A:4B:35:85 on Port 31 
Traceback (most recent call last): 
    File "T_C_1.py", line 40, in <module> 
    sock.connect((host, port)) 
    File "C:\Python 3.5\lib\site-packages\bluetooth\msbt.py", line 72, in connect 
    bt.connect (self._sockfd, addr, port) 
OSError: The requested address is not valid in its context. 

を、私は理由を把握することができません。一部のサイトでは、自分のホストアドレスがローカルマシン上にある必要があることを伝えています。 このコードは、Bluetooth経由でAndroid電話に接続しようとすると、WIndowsマシンから実行されます。 私は理由/方法を取得しません... ヘルプありがとう!

答えて

0

私はバインドエラーを受け取った後、私のMac環境を離れなければならなかったので、私はWindowsでPyBluezを使って同じエラーに遭遇しました。私は、あなたが外国のIPアドレスにバインドしているときや、システムで知られていない(例えば公的IP以外の)IPアドレスにバインドしているときに問題が発生していることを知りました。 PyBluezでaddrを '' 'にしてサーバを作成し、それに接続しようとしてみてください。それがうまくいかない場合は、そこからあなたの問題をさらに診断することができます。申し訳ありませんが、私はStackOverflowの新機能ですが、正確にはコメントできませんでしたが、私はいくつかの助けをしたいと考えていました。

関連する問題