DHyuk
DHyuk

Reputation: 13

How can I upload files avoiding "413 Request Entity Too Large" error message? using Python, requests module

I am trying to automate a web based analysis that requires two input files and DNA sequence string as input.

I have a lot of files and DNA sequence that I would like to analyze.

If I manually fill in the form on the website, it nicely work.

However, if I used the following script, it gives "413 Request Entity Too Large" error message.

How can I overcome this?

import requests
import gzip

url = "http://www.rgenome.net/cas-analyzer/#!"
s = requests.session()
r1 = s.get(url)
print(r1.cookies)
csrf_token = r1.cookies['csrftoken']

R1 = gzip.open("R1_001.fastq.gz", 'rt')
R2 = gzip.open("R2_001.fastq.gz", 'rt')
data = {'csrfmiddlewaretoken': csrf_token, 'file1': R1, 'file2': R2, 'fullseq': "atggccggttaaggttaaagg", 'rgneweq': 'atgccat'}

r2 = s.post(url=url, data=data, headers={'Content-Type': 'application/x-www-form-urlencoded'})
print(r2)
print(r2.text)
R1.close()
R2.close()

I have try this.

R1 = open("R1_001.fastq.gz", 'rb')
R2 = open("R2_001.fastq.gz", 'rb')

But it doesn't make any difference.

The server is not under my control. Funny thing is that I can do it manually on the webpage but I can not use the script

Upvotes: 1

Views: 4820

Answers (1)

Rohit Kumar
Rohit Kumar

Reputation: 719

A 413 Request Entity Too Large error occurs when a request made from a client is too large to be processed by the web server.

If your web server is setting a particular HTTP request size limit, clients may come across a 413 Request Entity Too Large response. in this this case uploading a large file.

if you are the one controlling webserver you might want to adjust the params in webserver config.

Sample Example

NGINX

server {
    client_max_body_size 100M;
    ...
}

APACHE

LimitRequestBody 104857600

Upvotes: 2

Related Questions