0
votes

I am currently working on a web-application using VueJS for the front-end and Django (Django Rest Framework) for the back-end.

One of the feature of the application is to send a pdf invoice by mail. So I was able to generate the pdf using "jspdf" library. And on Django side, I made an API end-point in order to send an email (with the pdf attached).

So the logic is (tell me if it's wrong to do that):

  • Converting the output pdf to Base64 on the front-end in order to post it to my "sendmail" endpoint with Axios.
  • Decoding the Base64 string on the back-end, write a temp pdf file, and attached it to send the mail.

It works perfectly, I tested it, the post request have a status 200. I receive the mail with the pdf attached... But on django side, I got "[Errno 54] Connection reset by peer".

Here's the full error:

[24/Nov/2020 21:50:53] "POST /api/sendmail/ HTTP/1.1" 200 0
--------------------------------------------
Exception happened during processing of request from ('127.0.0.1', 59267)
Traceback (most recent call last):
  File "/Users/jjj/anaconda3/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/Users/jjj/anaconda3/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/jjj/anaconda3/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/Users/jjj/Documents/DEV/Environments/project1_env/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 174, in handle
    self.handle_one_request()
  File "/Users/jjj/Documents/DEV/Environments/project1_env/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/Users/jjj/anaconda3/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

The thing is that I tried to do a post request with Postman and it worked without any error... which drives me crazy. So I suspect the error to be on the front side.

Here's my vue side code:

sendInvoice() {
    var mailInfo = {
        email: this.currentOrder.email,
        pdf: printPDF(this.currentOrder, true)
    }

    this.postSendMail(mailInfo)
}

and here's my axios code:

postSendMail(context, mailInfo) {
    return new Promise((resolve, reject) => { 
        getAPI.post('/sendmail/', mailInfo) 
            .then(() => {
                resolve()
            })
    }) 
},

Do you have any ideas...? Thanks in advance.

1
Does this answer your question : stackoverflow.com/questions/57261024/…Ajay Lingayat
Nope, I don't have any problem when I start my project, I only do when I do the post request mentioned above...josh__

1 Answers

0
votes

Okay, I feel very dumb right now. I just spent 3 hours trying to understand the error.

The reason was that in my axios instance I set the timeout to 1000... and since my Base64 pdf string is quite heavy, it takes more than 1 second. I just set it to 5000 and it works perfectly now!