我正在使用PyQT4开发一个应用程序,它将一些数据发送到Web服务以发送SMS。该应用程序在Ubuntu 10.04上运行良好。但是当我在Windows上部署它时,我得到BadStatusLine错误。我在Windows 7上运行Python 2.6.4。
错误消息和源代码如下。我没有放gui.py,因为它是由Qt Designer自动生成的。
请帮我调试一下。
错误消息:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python26\lib\threading.py", line 525, in __bootstrap_inner
self.run()
File "D:\Temp\gp\library.py", line 14, in run
f = urllib2.urlopen(urllib2.Request("http://masnun.com/aloashbei/sms/send",u
rllib.urlencode(self.data)))
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = self._open(req, data)
File "C:\Python26\lib\urllib2.py", line 407, in _open
'_open', req)
File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 1146, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python26\lib\urllib2.py", line 1119, in do_open
r = h.getresponse()
File "C:\Python26\lib\httplib.py", line 974, in getresponse
response.begin()
File "C:\Python26\lib\httplib.py", line 391, in begin
version, status, reason = self._read_status()
File "C:\Python26\lib\httplib.py", line 355, in _read_status
raise BadStatusLine(line)
BadStatusLine
App.Py
#!/usr/bin/python
import os, sys
from PyQt4 import QtCore, QtGui
import gui, library
app = QtGui.QApplication(sys.argv)
mainWindow = QtGui.QMainWindow()
mainWindow.ui = gui.Ui_MainWindow()
mainWindow.ui.setupUi(mainWindow)
appUi = mainWindow.ui
# Add the application logic
handler = library.Application(mainWindow)
appUi.sendButton.clicked.connect(handler.send)
appUi.actionQuit.triggered.connect(sys.exit)
mainWindow.show()
sys.exit(app.exec_())
library.py
#!/usr/bin/python
from PyQt4 import QtGui
from threading import Thread
class Req(Thread):
def __init__(self,data,callback):
self.data = data
self.callback = callback
Thread.__init__(self)
def run(self):
import urllib, urllib2, json
f = urllib2.urlopen(urllib2.Request("http://masnun.com/aloashbei/sms/send",urllib.urlencode(self.data)))
resp = json.loads(f.read())
status = resp['SendSMSResponse']['status']
self.callback(status)
#8801711960803
class Application(object):
def __init__(self,mainWindow):
self.mainWindow = mainWindow
self.ui = mainWindow.ui
self.status = ""
def quit(self):
import sys
sys.exit()
def send(self):
data = {}
data['registrationID'] = self.ui.username.text()
data['password'] = self.ui.password.text()
data['sourceMsisdn'] = self.ui.phoneNumber.text()
data['destinationMsisdn'] = self.ui.toBox.text()
data['smsPort'] = 7424
data['msgType'] = 4
data['charge'] = 0.00
data['chargedParty'] = self.ui.phoneNumber.text()
data['contentArea'] = 'gpgp_psms';
data['msgContent'] = self.ui.smsText.text();
req = Req(data,self.getStatus)
req.start()
req.join()
if self.status == 'OK':
QtGui.QMessageBox.information(None,"SMS Sent","SMS Sent successfully!")
self.status = ""
else:
QtGui.QMessageBox.critical(None, "ERROR!","The SMS could not be sent!",QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default,QtGui.QMessageBox.NoButton)
self.status = ""
def getStatus(self,status):
self.status = status
答案 0 :(得分:0)
嗯,我刚认识它。你不能混淆Unicode和字符串。我还使用了urllib而不是urllib2。有效。但我还不确定问题出在哪里:(