开发者

BadStatusLine Error in Python (On Windows Only)

I am developing an application with PyQT4 which will POST some data to a web service to send SMS. The application works perfectly on Ubuntu 10.04. But when I deploy it on Windows, I get the BadStatusLine Error. I am running Python 2.6.4 on Windows 7.

The Error Message and the source codes follow. I didn't put the gui.py since it was auto generated by the Qt Designer.

Please help me debug it.

Error Message:

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.t开发者_如何转开发ext()
        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


Well, I just got id of it. You can not mix up Unicode and Strings. I also used urllib instead of urllib2. It worked. But I am not yet sure where the problem came from :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜