Search code examples
pythonfetchcoap

aiocoap fetch method not allowed


The output of the command python3 -m aiocoap.cli.defaults is :

Python version: 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0]
aiocoap version: 0.4.1
Modules missing for subsystems:
dtls: missing DTLSSocket
oscore: everything there
linkheader: everything there
prettyprint: everything there
Python platform: linux
Default server transports: oscore:tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Selected server transports: oscore:tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Default client transports: oscore:tcpclient:tlsclient:ws:udp6
Selected client transports: oscore:tcpclient:tlsclient:ws:udp6
SO_REUSEPORT available (default, selected): True, True

I run as server aiocoap-rd. Then i run the following command to run RD client :

aiocoap-client --method FETCH --content-format 40 --payload '' --accept 40 coap://localhost/resource-lookup/?rt=temperature-c

I get this error :

4.05 Method Not Allowed
Traceback (most recent call last):
File "/home/aiocoap/.local/bin/aiocoap-client", line 8, in <module>
  sys.exit(sync_main())
File "/home/aiocoap/.local/lib/python3.8/site-packages/aiocoap/cli/client.py", line 361, in sync_main
  asyncio.get_event_loop().run_until_complete(single_request(args))
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
  return future.result()
File "/home/aiocoap/.local/lib/python3.8/site-packages/aiocoap/cli/client.py", line 304, in single_request
  present(response_data, options, file=sys.stderr)
File "/home/aiocoap/.local/lib/python3.8/site-packages/aiocoap/cli/client.py", line 123, in present
  prettyprinted = pretty_print(message)
File "/home/aiocoap/.local/lib/python3.8/site-packages/aiocoap/util/prettyprint.py", line 69, in pretty_print
  parsed = linkformat.link_header.parse(message.payload.decode('utf8'))
File "/home/aiocoap/.local/lib/python3.8/site-packages/link_header.py", line 87, in parse
  raise ParseException("link_header.parse() failed near %s", repr(scanner.buf)) link_header.ParseException: ('link_header.parse() failed near %s', "'Error: Method not allowed!'")

The GET method works fine.

Any help ?


Solution

  • The FETCH method is not defined for the resources of a Resource Directory, and thus not implemented on the RD server.

    In general, a FETCH should only be tried when there is some indication (either generally from the high-level protocol that is being used, or in concrete from an earlier browsing step eg. through some kind of form mechanism) that FETCH is available; that source will also tell you what to send in the FETCH request (for there should be a nontrivial payload with it, otherwise it could just as well have been a GET).