infiniflow / ragflow

RAGFlow is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding.
https://ragflow.io
Apache License 2.0
21.08k stars 2.06k forks source link

[Bug]: API Endpoints 'Upload file' do not operate as expected #2011

Closed FinTechCao closed 2 months ago

FinTechCao commented 2 months ago

Is there an existing issue for the same bug?

Branch name

main

Commit ID

0000

Other environment information

No response

Actual behavior

the result is {'data': None, 'retcode': 100, 'retmsg': "AttributeError("'NoneType' object has no attribute 'strip'")"}

Expected behavior

No response

Steps to reproduce

self.url_prefix+end_point = 'http://xxx.xx:8080/v1/api/document/upload'
self.headers_json = {'Content-Type': 'application/json', 'Authorization': 'Bearer ragflow-XXX'}

end_point = "/api/document/upload"
with open(file_path, "r") as f:
    file_content = f.read()
params = {"file": file_content,
          "kb_name": kb_name,
         }
req = requests.post(url=self.url_prefix+end_point, headers=self.headers_json, data=json.dumps(params))
content = req.json()

Additional information

No response

KevinHuSh commented 2 months ago

it seems that kb_name is none.

FinTechCao commented 2 months ago

it seems that kb_name is none.

I have already entered the kb_name parameter through

params = {"file": file_content,
          "kb_name": kb_name,
         }

and kb_name is not none

And the Docker image version is dev

KevinHuSh commented 2 months ago

May this help

FinTechCao commented 2 months ago

May this help

Thank you。 I changed the code to:

files = {'file': open(file_path, 'rb')}
data = {
            'kb_name': kb_name,
            'parser_id': 'naive'
        }
req = requests.post(url=self.url_prefix+end_point, headers=self.headers_json, files=files, data=data)

but the response is

{'data': None, 'retcode': 101, 'retmsg': 'required argument are missing: kb_name; '}
FinTechCao commented 2 months ago

I have fixed it by myself, you should write like this:

end_point = "/api/document/upload"
header = {"Authorization": "Bearer " + self.api_key}

files = {'file': open(file_path, 'rb'),
             'kb_name': (None, kb_name),
             'parser_id': (None, parser_id),
             'run': (None, "1")}
req = requests.post(url=self.url_prefix+end_point, headers=header, files=files)
babyporgrammer commented 1 month ago
    url = f"{self.base_url}/api/document/upload"

    headers = {
        "Authorization": f"Bearer {self.api_key}"
    }

    files = {'file': open(file_path, 'rb'),
             'kb_name': (None,"123123"),
             'parser_id': (None,"naive"),
             'run': (None,"1")}
    response = requests.post(url, files=files, headers=headers,verify=False)

I use the same code, but the error still same {'data': None, 'retcode': 100, 'retmsg': 'AttributeError("\'NoneType\' object has no attribute \'split\'")'}