Microsoft Windows Version 22H2 (Win10)
Version: 25.2.5.2 (X86_64) / LibreOffice Community
Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022
CPU threads: 2; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
I’m setting up an app that makes http HEAD requests. The http client that comes with Windows 10 and the http client in the OAuth2OOo extension are blocked or banned at some URLs. Curl gets around these blocks & bans somehow, but has to be called in Shell(), which creates other problems. I’ve tried changing the User-Agent header in the Win & OAuth2OOo clients to “curl/8.13.0” but that doesn’t create any improvement.
So I’m trying to test the Python urllib library. According to the comments in the request.py file, “The simplest way to use this module is to call the urlopen function, which accepts a string containing a URL or a Request object…” Since I know nothing about Python, I’m interested in simple things.
So…
Sub TestUrllibUrlopenFunction
	Dim objScriptProvider	As Object
	Dim objRequest			As Object
	Dim objResponse			As Object
	Dim strUri				As String
	
	objScriptProvider = ThisComponent.getScriptProvider
	strUri = "vnd.sun.star.script:urllib/request.py$urlopen?language=Python&location=user"
	objRequest = objScriptProvider.getScript(strUri)
	objResponse = objRequest.invoke(array("https://atun-rsia.org/resources"), array(), array())
End Sub
This results in
BASIC runtime error.
An exception occurred 
Type: com.sun.star.uno.RuntimeException
Message: Error during invoking function urlopen in module file:///C:/Users/user/AppData/Roaming/LibreOffice/4/user/Scripts/python/urllib/request.py (<class 'AttributeError'>: module 'http.client' has no attribute '_create_https_context'
  File "C:\Program Files\LibreOffice\program\pythonscript.py", line 921, in invoke
    ret = self.func( *args )
  File "C:\Users\user\AppData\Roaming\LibreOffice\4\user\Scripts\python\urllib\request.py", line 184, in urlopen
    _opener = opener = build_opener()
  File "C:\Users\user\AppData\Roaming\LibreOffice\4\user\Scripts\python\urllib\request.py", line 565, in build_opener
    opener.add_handler(klass())
  File "C:\Users\user\AppData\Roaming\LibreOffice\4\user\Scripts\python\urllib\request.py", line 1363, in __init__
    context = http.client._create_https_context(http_version)
).
OK, try the other simple thing.
Sub TestUrllibRequestObject
	Dim objScriptProvider	As Object
	Dim objRequest			As Object
	Dim objResponse			As Object
	Dim strHeaders			As String
	Dim strUri				As String
	
	objScriptProvider = ThisComponent.getScriptProvider
	strUri = "vnd.sun.star.script:urllib/request.py$Request?language=Python&location=user"
	objRequest = objScriptProvider.getScript(strUri)
	strHeaders = "If-Modified-Since: Mon, 01 Sep 2025 00:00:00 GMT"
	objResponse = objRequest.invoke(array("https://atun-rsia.org/resources"), _
		array("headers={" & strHeaders & "}"), array("method=HEAD"))
End Sub
Result:
BASIC runtime error.
An exception occurred 
Type: com.sun.star.uno.RuntimeException
Message: Couldn't convert <ooo_script_framework.Request object at 0x000002D5C93CAEF0> to a UNO type; caught exception: <class 'AttributeError'>: 'Request' object has no attribute 'getTypes', traceback follows
no traceback available
.
What am I doing wrong?