1

In my project I have requests library that sends POST request. Url for that request is hardcoded in function, which is accessed from views.py.

The problem is that when I dont have internet connection, or host, on which url is pointing, is down, I cant launch developer server, it gets stuck on Performing system check. However, if I comment the line with url, or change it to guarantee working host, check is going well.

What is good workaround here ?

views.py

def index(request):
    s = Sync()
    s.do()
    return HttpResponse("Hello, world. You're at the polls index.")

sync.py

class Sync:
    def do(self):
        reservations = Reservation.objects.filter(is_synced=False)
        for reservation in reservations:
            serializer = ReservationPKSerializer(reservation)
            dictionary = {'url': 'url', 'hash': 'hash', 'json': serializer.data}
            encoded_data = json.dumps(dictionary)
            r = requests.post('http://gservice.ca29983.tmweb.ru/gdocs/do.php', headers={'Content-Type': 'application/json'}, data=encoded_data)
            if r.status_code == 200:
                reservation.is_synced = True
                reservation.save()
Alexey K
  • 6,537
  • 18
  • 60
  • 118

1 Answers1

0

It might appear to be stuck because requests automatically retries the connection a few times. Try reducing the retry count to 0 or 1 with:

Can I set max_retries for requests.request?

kichik
  • 33,220
  • 7
  • 94
  • 114