ipfshttpclient.exceptions.StatusError: HTTPError: 405 Client Error: Method Not Allowed for url: http+ip4://127.0.0.1:5001/api/v0/version?stream-channels=true

ipfs version 0.5.1
ipfshttpclient-0.4.13.2


Ipfs is already running on the background using (nohup ipfs daemon &). Afterwards I tried to obtain already connected ipfs’s client.

$ ipfs config Addresses
{
  "API": "/ip4/127.0.0.1/tcp/5001",
  "Announce": [],
  "Gateway": "/ip4/127.0.0.1/tcp/8080",
  "NoAnnounce": [],
  "Swarm": [
    "/ip4/0.0.0.0/tcp/4001",
    "/ip6/::/tcp/4001"
  ]
}

import ipfshttpclient

client = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001/http')

=> What may be the reason of this error? How could I fix it?


Error log:

❯ ./ipfs_daemon.py
[2020-06-04 02:48:12          lib.py:314 -         is_process_on()] IPFS is already running on the background
Traceback (most recent call last):
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/http.py", line 266, in _do_raise_for_status
    response.raise_for_status()
  File "/home/alper/venv/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: http+ip4://127.0.0.1:5001/api/v0/version?stream-channels=true

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./ipfs_daemon.py", line 30, in <module>
    client = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001/http')
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/client/__init__.py", line 101, in connect
    version_str = client.version()["Version"]
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/client/base.py", line 15, in wrapper
    result = func(*args, **kwargs)
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/client/miscellaneous.py", line 204, in version
    return self._client.request('/version', decoder='json', **kwargs)
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/http.py", line 51, in wrapper
    return func(self, *args, **merged)
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/http.py", line 386, in request
    username, password, data, timeout)
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/http.py", line 307, in _request
    self._do_raise_for_status(res)
  File "/home/alper/venv/lib/python3.7/site-packages/ipfshttpclient/http.py", line 286, in _do_raise_for_status
    six.raise_from(exceptions.StatusError(error), error)
  File "<string>", line 3, in raise_from
ipfshttpclient.exceptions.StatusError: HTTPError: 405 Client Error: Method Not Allowed for url: http+ip4://127.0.0.1:5001/api/v0/version?stream-channels=true

I’m having this same error, could you pin down what it was?

I could not find a solution. I have also opened a issue on their github page but it did not see much attention. https://github.com/ipfs-shipyard/py-ipfs-http-client/issues/218#issue-630403822

So I cloned the developing version from github

git clone https://github.com/ipfs/py-ipfs-http-client.git

And I’m getting a different error now, so I guess it’s an improvement haha

Check out now it is fixed on the latest version

I’m trying to solve this error too, are there a solution?

Either the client is using GET instead of POST methods (because it is out of date), or CORS is not correctly configured. Probably the python client needs to be patched to use POST.

import ipfshttpclient
import requests

client = ipfshttpclient.connect(’/ip4/127.0.0.1/tcp/5001/http’)
print(client)

@app.route(’/sendfileipfs’,methods=[‘POST’])
def ipsffiles():
with open(‘output.json’) as f:
file_data = json.load(f)
return file_data

if name == ‘main’:
app.run(debug=True,port=5050)

I have like this but don’t work