Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QNetworkReply doesn't abort/close

QNetworkReply doesn't abort/close

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan252
    wrote on last edited by
    #1

    My Code: (relevent parts)
    @

    def update(self):
        request = QNetworkRequest()
        request.setUrl(QUrl("someurl"))
        self.network_manager.finished.connect(self._update)
        self.network_manager.get(request)
    
    def _update(self, reply): # update stage 2    
        if not reply.error() == QNetworkReply.NoError:
            # request probably failed
            print(reply.error())
            print(reply.errorString())
            print("retrying")
            self.update()
        else:
            reply.abort()
            #print(str(reply.readAll().data()))
            data = json.loads(str(reply.readAll().data())) # get data
            #work with the data (irrelevant)
    
    def sendBearer_req(self):
    
        request = QNetworkRequest()
        request.setUrl(QUrl("someotherurl"))
    
        self.network_manager = QNetworkAccessManager()
        self.network_manager.finished.connect(self._request_finished)        
    
        self.network_manager.post(request, self.urlencode_post({'some' : 'thing'}))
    
    def sendBearer(self, reply):
        reply.abort()
        ans = reply.readAll()        
        print(ans)
        time.sleep(5)
        print(ans)
    
        try:
            self.bearer = json.loads(str(ans))                
            self.update()            
        except:
            raise #for debugging
            self.sendBearer_req() #retry        
    
    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)@
    

    Problem:

    it's in this part:
    @
    reply.abort()
    ans = reply.readAll()
    print(ans)
    time.sleep(5)
    print(ans)@
    I'm pretty sure the abort isn't working because on the first print it prints just what i want but then, while it waits, apparently it continues with the code and enters the update function where it sends another request. Therefor in the second print the two replies mix together and it prints the both.

    (btw I tried close as well - same result)

    What am I doing wrong?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johnjohn31
      wrote on last edited by
      #2

      what about sleep do you process when you sleep ?
      try :
      @while reply.isReadable () :

      ans = ans + reply.read()

      print (ans)@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved