python - read string (IP addr) from file not the same as assign manually -
i want read ip address config file , use in socket udp transfer.
import configparser # read config file , create constants cfgfile = 'omc-mt.cfg' config = configparser.configparser() config.sections() config.read(cfgfile) #print(config.sections()) addr = config['addr'] pc_ip = addr['osc_ip'] pc_port = int(addr['osc_port']) in socket.bind
pc_rxsock = socket.socket(socket.af_inet, socket.sock_dgram) pc_rxsock.bind((pc_ip, pc_port)) i'll error:
oserror: [errno 49] can't assign requested address
if compare read string , manually assigned find no differences:
pc_ip2 = '192.168.2.110' print (len(pc_ip)) print (len(pc_ip2)) at least same when print , @ same length. suppose has text encoding have no idea how fix it. text file saved utf-8 (editors says). use idle / python 3.4.2. cheers
content of omc-mt.cfg:
[addr] # ip address , port of osc device e.g. smartphone or tablet osc_ip = 192.168.2.100 osc_port = 54047 # mastertone ip address mt_ip=192.168.2.200 mt_port=5001 # computer's ip , udp ports # rx port must match tx port set in osc software pc_ip = 192.168.2.110 #pc_ip = 192.168.1.26 pc_port = 5005
consider these lines:
pc_ip = addr['osc_ip'] pc_port = int(addr['osc_port']) i suppose want:
pc_ip = addr['pc_ip'] pc_port = int(addr['pc_port'])
Comments
Post a Comment