0

这是我的代码:

import serial
import time
import socket
ip = str('url')
port = int(6090)
err = 0
try:
    mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mySocket.connect((ip, port))
    while 1:
        arduino = serial.Serial('/dev/ttyACM0', 9600)
        sensorValue = arduino.readline()
        mySocket.sendall(sensorValue)
except socket.error, msg:
    mySocket.close()
    print 'socket error', msg
mySocket.close

运行此程序后,我收到此消息“套接字错误 [Errno -3] 名称解析临时失败”。有人可以帮我解决这个问题吗?

4

1 回答 1

0

根本问题是/etc/resolv.conf仅在 python 启动时读取。要强制刷新解析表,您可以运行它(在 linux 上):

import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
res_init = libc.__res_init
res_init()
于 2016-05-23T21:38:19.297 回答