Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#30503 closed Bug (invalid)

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host.

Reported by: Rajkumar Srinivasan Owned by: nobody
Component: HTTP handling Version: dev
Severity: Normal Keywords: paytm payments
Cc: msrajkumar95@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am getting below issue while processing paytm payments and returning back to my Django application.
Below is my code in views.py

from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.conf import settings
from paytm import checksum
from paytm.models import PaymentHistory

@login_required
def payment(request):
    CALLBACK_URL = settings.HOST_URL + settings.PAYTM_CALLBACK_URL
    order_id = checksum.__id_generator__()

    bill_amount = request.POST['amount']
    if bill_amount:
        data_dict = {
                    'MID':settings.PAYTM_MERCHANT_ID,
                    'ORDER_ID':order_id,
                    'TXN_AMOUNT': bill_amount,
                    'CUST_ID':request.user.email,
                    'INDUSTRY_TYPE_ID':settings.PAYTM_INDUSTRY_TYPE,
                    'WEBSITE': settings.PAYTM_WEBSITE,
                    'CHANNEL_ID':'WEB',
                    'CALLBACK_URL':CALLBACK_URL,
                }
        param_dict = data_dict
        param_dict['CHECKSUMHASH'] = checksum.generate_checksum(data_dict, settings.PAYTM_MERCHANT_KEY)
        return render(request,"paytm/payment.html",{'paytmdict':param_dict})
    return HttpResponse("Bill Amount Could not find. ?bill_amount=10")

@login_required
@csrf_exempt
def response(request):
    if request.method == 'GET':
        return render(request, 'paytm/home.html')
    elif request.method == "POST":
        data_dict = {}
        for key in request.POST:
            data_dict[key] = request.POST[key]
        verify = checksum.verify_checksum(data_dict, settings.PAYTM_MERCHANT_KEY, data_dict['CHECKSUMHASH'])
        if verify:
            for key in request.POST:
                if key == "BANKTXNID" or key == "RESPCODE":
                    if request.POST[key]:
                        data_dict[key] = int(request.POST[key])
                    else:
                        data_dict[key] = 0
                elif key == "TXNAMOUNT":
                    data_dict[key] = float(request.POST[key])
            PaymentHistory.objects.create(user=request.user, **data_dict)
            return render(request,"paytm/response.html",{"paytm":data_dict})
        else:
            return HttpResponse("checksum verify failed")
    return HttpResponse(status=200)

Code in urls.py

from django.urls import path
from paytm import views

urlpatterns = [
    path('', views.response, name='home'),
    path('payment/', views.payment, name='payment'),
    path('response/', views.response, name='response'),
]

Here's my trace back exception details.

[12/May/2019 08:38:35] "POST /paytm/payment/ HTTP/1.1" 200 4005
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54543)
Traceback (most recent call last):
  File "C:\Python\Python37\lib\socketserver.py", line 647, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python\Python37\lib\socketserver.py", line 357, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python\Python37\lib\socketserver.py", line 717, in __init__
    self.handle()
  File "C:\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line 
171, in handle
    self.handle_one_request()
  File "C:\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line 
179, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "C:\Python\Python37\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by 
the remote host
----------------------------------------
[12/May/2019 08:39:25] "POST /paytm/response/ HTTP/1.1" 200 3154

Change History (2)

comment:1 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed
Summary: ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote hostConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host.
Version: 2.2master

Thanks for the report, however IMO it is some Windows issue related with sockets maybe antivirus or firewall blocks connections, it is hard to tell. Nevertheless it is a support issue.

Closing per TicketClosingReasons/UseSupportChannels.

comment:2 by Carlton Gibson, 4 years ago

Is this not just the browser shutting the connection, after some time perhaps? (What’s the keep-alive timeout?)

I see this kind of thing on macOS all the time:

[12/May/2020 10:29:46] "GET /admin/jsi18n/ HTTP/1.1" 200 5739
[12/May/2020 10:29:46] "GET /static/admin/css/widgets.css HTTP/1.1" 200 4096
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 56275)
Traceback (most recent call last):
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/Users/carlton/Documents/Django-Stack/django/django/core/servers/basehttp.py", line 174, in handle
    self.handle_one_request()
  File "/Users/carlton/Documents/Django-Stack/django/django/core/servers/basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
----------------------------------------
[12/May/2020 10:29:46] "GET /favicon.ico HTTP/1.1" 404 1972
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 56276)
Traceback (most recent call last):
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/Users/carlton/Documents/Django-Stack/django/django/core/servers/basehttp.py", line 174, in handle
    self.handle_one_request()
  File "/Users/carlton/Documents/Django-Stack/django/django/core/servers/basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/Users/carlton/.pyenv/versions/3.6.0/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

It’s expected behaviour.

Note: See TracTickets for help on using tickets.
Back to Top