将内容上传到网站的问题

时间:2015-11-23 08:28:33

标签: python html

我只是一个新学习的程序员。我希望通过python将一些数字上传到我的网站但有些我失败了。你能帮我弄清楚出了什么问题吗?

这是我原来的python代码。

#!/usr/bin/python
import time
import urllib.request 
import random
import datetime
from urllib.request import Request,urlopen
basic_web = 'http://ihome.ust.hk/~xxxxx/cgi-bin/datafile.php?'
message=""

while(True):
    local_time= time.time()
    web_x = basic_web

    file1 = open("datalist1.txt", "r")
    queue1 = file1.read()    
    file1.close()
    web_x += "&queue1=" + queue1

    file2 = open("datalist2.txt", "r")    
    queue2 = file2.read()    
    file2.close()
    web_x += "&queue2=" + queue2

    web_x += "&local_time=" + str (local_time)
    print (web_x)
    #req = Request (web_x)
    #html = urlopen(req).read()
    response = urllib.request.urlopen(web_x, timeout = 1)
    html = response.read()
    print(html)
    time.sleep(0.1)
    print ("hehe")

这是我得到的输出错误:

    Traceback (most recent call last):
  File "C:\web bus stop\local\datauploader.py", line 25, in <module>
    response = urllib.request.urlopen(web_x)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 162, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 465, in open
    response = self._open(req, data)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 483, in _open
    '_open', req)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 443, in _call_chain
    result = func(*args)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 1268, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 1243, in do_open
    r = h.getresponse()
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 1174, in getresponse
    response.begin()
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 282, in begin
    version, status, reason = self._read_status()
  File "C:\Users\ad\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 264, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine:  connected! queue1queue2 finish sir!

如果你们能帮助我找出错误是什么,我真的很感激。

1 个答案:

答案 0 :(得分:0)

没关系。 我更换了一台计算机来运行它,现在它已经运行了。