remboldt / ipfslib

A simple IPFS Library for Python, which actually works
0 stars 1 forks source link

resolve.py creating an error #1

Open ent1tydev opened 11 months ago

ent1tydev commented 11 months ago

Traceback (most recent call last): File "C:\Users\user\Desktop\coin\main.py", line 6, in <module> cid = ipfslib.IPFS.resolve(api, ipns_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\ipfslib\IPFS\resolve.py", line 13, in resolve return json.loads(raw_json)['Path'] ^^^^^^^^^^^^^^^^^^^^ return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

resolve.py fix:

` import json import requests

def resolve(api, ipns_name): response = requests.post('http://{endpoint}/api/v0/name/resolve/{ipns_name}'.format(endpoint=api.endpoint, ipns_name=ipns_name)) raw_json = response.text try: data = json.loads(raw_json) return data['Path'].replace('/ipfs/', '') except KeyError: raise Exception('IPNS resolution failed: {}'.format(response.text)) `

remboldt commented 11 months ago

Thanks! I'll update it tomorrow