python使用socket远程连接错误处理方法
2015-04-29 14:46
1076 查看
import socket, sys host = sys.argv[1] textport = sys.argv[2] filename = sys.argv[3] try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) except socket.error, e: print "Strange error creating socket: %s" % e sys.exit(1) try: port = int(textport) except ValueError: print "Couldn't find your port: %s" % e sys.exit(1) try: s.connect((host, port)) except socket.gaierror, e: print "Address-related error connecting to server: %s" % e sys.exit(1) except socket.error, e: print "Connection error: %s" % e sys.exit(1) try: s.sendall("GET %s HTTP/1.0\r\n\r\n" % filename) except socket.error, e: print "Error sending data: %s" % e sys.exit(1) while 1: try: buf = s.recv(2048) except socket.error, e: print "Error receiving data: %s" % e sys.exit(1) if not len(buf): break sys.stdout.write(buf)
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- python使用socket远程连接错误处理方法
- python使用socket连接远程服务器的方法
- python使用socket连接远程服务器的方法
- python实现带错误处理功能的远程文件读取方法
- python使用socket进行简单网络连接的方法
- python实现带错误处理功能的远程文件读取方法
- 仅允许运行使用网络级别身份验证的远程桌面计算机连接失败处理方法(远程桌面连接)
- 使用sqlyog远程连接mysql 错误2003 cant connect to mysql 10060/10061 解决方法最强合集
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- C# UDP Socket 远程主机强行关闭了一个连接的处理方法
- 使用SQLyog远程连接mysql,以及mysql远程连接错误1130 解决方法
- Python django使用多进程连接mysql错误的解决方法
- python使用TensorFlow进行图像处理的方法
- python 中使用with简化MySQL 和 Socket 的连接
- 解决远程连接mysql错误1130代码的方法
- 一种解决Android进行蓝牙连接时发生socket已关闭或超时错误的方法
- C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误的解决方法