Calc, Basic invoked python script fails after reopening file

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
holmis93
Posts: 2
Joined: Fri Dec 22, 2017 8:29 pm

Calc, Basic invoked python script fails after reopening file

Post by holmis93 »

Hello!

Ill get straight to the point. Im using Calc to analyze some data that I automatically get from the internet. I have written a BASIC script that in turn calls a python script that obtains the actual data from an url and then returns it to BASIC who does some additional processing before sending it back into calc. My actual issue is not really anything with the functionality since it works exactly is a want it to, except not all the time...

If i create a blank project and use my macros and it will work well without any issues whatsoever. But when I save a file and exit then reopen calc and the same file the macros will no longer work. This first occured when i was using OpenOffice 4.1.4, therefore i tested an earlier version (4.0) and i was happy for awhile since it seemed to work. I could save files open them up again and everything would still work as intended.But then for some reason, that I have not been able to determinate, the same issue appeared once more.

Now a little more detail of what happens. This examples are not the full scripts but just some debug scripts that showcase the issue. As i mentioned I utilize a basic macro to call my python script in a manner akin to this:

Code: Select all

Function Element(p1)
    sURL = "vnd.sun.star.script:pythonscripts.py$Element?language=Python&location=share"
    oMSP = ThisComponent.getScriptProvider()
    oScript = oMSP.getScript(sURL)
    
    Element = oScript.invoke(array(p1), array(), array() )
End Function
Now the failing part of the python script:

Code: Select all

import urllib2

def Element(*args):
         sock = urllib2.urlopen(args[0])
         html = sock.read()
         sock.close()

         return html
As you can see my script uses the urllib2 to retrieve the data that I want. Very simple and straight forward, and it should work, as it does until a document is saved and reopened. At that point when Calc attempts to call my macros to retrieve new data the following error will occur, no matter how many times i attempt re-invoke the macro:

Image

It now complains that urllib2 cannot get the data since it does not understand what a https url is. This is a very strange error to get since from my research this error is most common when python itself has been compiled in the working way. Obviously this should not be the case since it works very well until you reopen a document. I have also tested to manually do the same steps in the included python interpreter to verify that it works and it does. As I said earlier I have also up till now tested on two different version of openoffice (4.0 and 4.1.4). After i switched to 4.0 it worked well for awhile then the error suddenly started to happen again. The most similar post that I could find on this forum is this one: viewtopic.php?f=45&t=72029. But this error does not really occur in the same way as the one im getting. Nevertheless, I attempted some of those suggestions to no avail. Further, i have also verified that i can indeed call other python scripts that do not use urllib2 and then it also works. That I think is even more strange, I would rather everything regarding python would fail not just using this specific lib. I also did some small testing with the request lib in python, but it seems to behave in the same way.

At this point I have been at this for a few nights this week and I have yet to find a solution, but I do not intend to give up, although if anyone have any idea what could be wrong that would be of great help. Some theories that I have that are not confirmed in any way include:
  • Privilege/administrative issues regarding the files used when invoking a script in this type of manner.

    The scripts being invoked to fast at startup after reopening the file.

    Other timing issues in regards to the order of things.

    When the file is saved some part is not stored correctly.

    OO Version issue.

    Python version isssue? I noticed that 4.0 runs in 2.7.5 and 4.1.4 runs in 2.7.6.

    Blocked by something in certain situations, firewall, virus program, other?? I have tested having fully disabled the firewall and anti virus, avast (that i uninstalled out of frustration :crazy: :lol: ), and the error still occurred.
    .
    .
    .
Some of these theories are somewhat pulled out of thin air but I am starting to run out of ideas. Again I know this issue is very specific and providing an exact answer could be difficult. But I am willing to try any ideas if anyone is willing to share them. I hope it is possible to derive some useful information from this text.

Regards,
Holmis
OpenOffice 4.0 / OpenOffice 4.1.4 on Windows 7
holmis93
Posts: 2
Joined: Fri Dec 22, 2017 8:29 pm

Re: Calc, Basic invoked python script fails after reopening

Post by holmis93 »

Update.

I installed OpenOffice version 3.4.1, and now it seemingly works again. Although it was the same when i first installed 4.0 down from 4.1.4, so I cannot be sure that the error wont arise when using 3.4.1 as well. Therefore I cant really say that the issue is solved, since it is still there in 4.x version and for all I know I could start my computer tomorrow and face the exact same issue with 3.4.1. I will continue to dig a bit further, and for now I will let the topic remain unsolved.
OpenOffice 4.0 / OpenOffice 4.1.4 on Windows 7
Post Reply