问题标题指出了我的问题。基本上,我目前正在尝试调试POST问题。在给定模板csv文件的情况下,用户用数据填充单元格。然后在网页上,提示用户上载文件,单击“提交”,并根据是否已将数据输入到数据库中返回成功或错误消息。解决了csv文件中的一些次要数据格式问题后,我最终看到了错误10060,显然是在Socket模块上出现的:
create_connection中的文件“ C:\ Users \ user \ AppData \ Local \ Programs \ Python \ Python27 \ lib \ socket.py”,第575行
提高错误
错误:[Errno 10060]连接尝试失败,因为一段时间后连接方未正确响应,或者由于连接的主机未能响应而建立连接失败
导致此问题的通用代码是这样的:
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
port)``) and return the socket object. Passing the optional
*timeout* parameter will set the timeout on the socket instance
before attempting to connect. If no *timeout* is supplied, the
global default timeout setting returned by :func:`getdefaulttimeout`
is used. If *source_address* is set it must be a tuple of (host, port)
for the socket to bind as a source address before making the connection.
A host of '' or port 0 tells the OS to use the default.
"""
host, port = address
err = None
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket(af, socktype, proto)
if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
if source_address:
sock.bind(source_address)
sock.connect(sa)
return sock
except error as _:
err = _
if sock is not None:
sock.close()
if err is not None:
raise err
else:
raise error("getaddrinfo returns an empty list")
我正在本地开发服务器上测试代码,我在Django v1.8和Python v2.7上运行这些代码,因为大多数代码已在两年前编程为那些版本。所有其他页面均正确加载,因为它似乎仅在发送POST提交CSV文件数据的请求时崩溃。我对套接字不太熟悉,所以我想知道是否有人会告诉我为什么会发生此错误。我一直在使用Exceptions调试数据导入代码,因此,如果在POST端发生任何错误,则控制台将输出在那里出错的信息。