简体   繁体   中英

500 internal error only when running from windows (7)

Problem: the program is facing a 500 Internal Error when accessing a website using this code: (I work with PyQt)

Happens only on my windows box (WIN7) and not on my linux (ubuntu 12.04 LTS) fyi they are different computers (but on the same LAN)

def sendBearer_req(self):
    request = QNetworkRequest()
    request.setUrl(QUrl("https://api.twitter.com/oauth2/token"))
    request.setRawHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
    request.setRawHeader('Authorization', 'Basic %s' % cons_enc)

    self.network_manager = QNetworkAccessManager()
    if self.network_manager.receivers(SIGNAL("finished")) > 0:
        self.network_manager.finished.disconnect()
    self.network_manager.finished.connect(self._request_finished)        

    self.network_manager.post(request, self.urlencode_post({'grant_type' : 'client_credentials'}))

def _request_finished(self, reply):
    if not reply.error() == QNetworkReply.NoError:
        # request probably failed
        print(reply.error())
        print(reply.errorString())
        print("retrying")
        self.sendBearer_req()
    else:
        self.sendBearer(reply)

Output:

299    
Error downloading URL - server replied: Internal Server Error    
retrying

where URL is the page url.


  • I tried it with many URLs in case the problem was really in the server itself but it's not.
  • cons_enc is valid (b64 encoded string)

How to fix it? and if you know why in ubuntu it works?

Status code 299 is non-standard and the Twitter API Error Code Reference does not list it. Likely the cause is not related to this stub of code

QNetworkReply defines code 299 as "unknown error", maybe it's a Qt bug.

As a suggestion, try using a proper Twitter API for Python .

Problem found, apparently I runned it accidently on Python 3.3 on windows and it was built for Python 2.7 (which was used in the linux box).

Maybe PyQt should check that before starting up!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM