Webservice Returns #Value from Valid Url

WEBSERVICE("https://wiki.documentfoundation.org/api.php?hidebots=1&days=7&limit=50&action=feedrecentchanges&feedformat=rss")

returns correctly but

WEBSERVICE("http://api.evemarketer.com/ec/marketstat?typeid=34")

returns #value
Does anyone have any info on how to fix this or how to work around said error
this service works on EXCEL and google sheets, im currently attempting to switch to libre.

[erAck: edited to mark code as code to not have Discourse interpret it but display instead; see This is the guide - How to use the Ask site? - #6 by erAck ]

1 Like

Note im using 7.3.3 64bit

api.evemarketer.com hides behind Cloudflare and Cloudflare is dumb enough to reject some clients not being a browser or that it doesn’t know or accept for no reason or with a HEAD request. Like for

curl -I --head 'http://api.evemarketer.com/ec/marketstat?typeid=34'

it returns a HTTP/1.1 500 Internal Server Error and with a -X OPTIONS request instead it returns completely nothing. LibreOffice uses libcurl announcing LibreOffice and curl in the User-Agent header.

Parsing User-Agent header considered harmful.

Update:

With Cloudflare it seems to be yet a different problem, apparently it answers any HEAD request with a 500 error, regardless of User-Agent string. In fact

curl 'http://api.evemarketer.com/ec/marketstat?typeid=34'

does deliver a result.

LibreOffice first sends an OPTIONS request, then HEAD, then GET. If already HEAD fails then it doesn’t attempt a GET. (if that still is the case, it’s some time ago I looked at it).

… and AFAICT mst made a change recently to workaround that - ah yes, it’s commit 8d9c56e8f42428fd6695942c673bffb985d22ad5. But that should be available in 7.3.3 already …

I have the same problem - LibreOffice Version: 7.5.9.2 (X86_64).

Trying to query HMRC exchange rates, but their site rejects the OPTIONS requests with a 422 error so LibreOffice doesn’t continue with the HEAD or GET and just displays #value

This may be overkill but I’m considering using something like MITM proxy to discard those bad requests

In the end I settled on a python script - see below.

To use it, just save the code and then start the server in a command line / terminal (this is for Linux, but the command prompt syntax would be relatively similar)

sudo python3 libreoffice-proxy.py (sudo not required if you use port > 1024)

Then, to use it from within Libreoffice, prepend http://localhost to the desired URL, e.g. to retrieve HMRC tax information you could do. This should work for both the Link External Data as well as the WEBSERVICE formula, e.g.

=WEBSERVICE("http://localhost/www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_2022-8.xml")

Supposing you have an existing cell, A2 with a date in that you’d like to use to query the exchange rates - and you want to find the HMRC monthly USD exchange rate for that month, you could use the following formula:

=FILTERXML(WEBSERVICE(SUBSTITUTE(WEBSERVICE("http://localhost/www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_{MONTH}.xml","{MONTH}",YEAR(A2)&"-"&MONTH(A2))),"//exchangeRate[countryCode = ""US""]/rateNew")

Here’s the code for the proxy server.

libreoffice-proxy.py

  1 import requests
  2 import socketserver
  3 import http.server
  4 import urllib
  5 
  6 port = 80
  7 
  8 class MyProxy(http.server.SimpleHTTPRequestHandler):
  9     def do_GET(self):
 10         url="https://" + self.path[1:]
 11         self.send_response(200)
 12         self.end_headers()
 13         print("attempting to retrieve ",url)
 14         r = requests.get(url) 
 15         self.wfile.write(r.text.encode('utf-8'))
 16 
 17     def do_HEAD(self):
 18         self.do_OPTIONS()
 19 
 20     def do_OPTIONS(self):
 21         self.send_response(204)
 22         self.end_headers()
 23 
 24 httpd = http.server.HTTPServer(('', port), MyProxy)
 25 print ("Now serving at",    str(port))
 26 try:
 27     #httpd.handle_request()
 28     httpd.serve_forever()
 29 finally:
 30     httpd.server_close()

1 Like