﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30503	ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host.	Rajkumar Srinivasan	nobody	"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
}}}
"	Bug	closed	HTTP handling	dev	Normal	invalid	paytm payments	msrajkumar95@…	Unreviewed	0	0	0	0	0	0
