• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Help With Java/Python/Jython Not Having Sufficient Permissions

Hardcore SysOp

Well-known member
Hello again, folks. Okay, old Mr. Bill is REALLY going to go off-topic with this message, but I am a really desperate man! :)

So here we .....

As a few of you here may possibly recall, for the 4th time since 1993, I recently resurrected my Hermes II BBS from several decades ago. Now to the issue. I am having one basic problem which neither I, nor ChatGPT, have figured out how to rectify, despite many hours working on it.

Basically, the Hermes II software that I use has its own Jython 2-based runtime environment. Within the file and folder structure of Hermes II, there is in fact a Jython folder, which among other things contains various packages, including a Hermes API package, a Jython package, a QT Java package, an MRJClasses package, as well as a few other things.

The python module I am creating is heavily based on the code of another BBS game which was quite popular within the BBS world quite a few years ago. That game is called Leech. Some of you older folks will no doubt be familiar with one flavor or another of this game.

At any rate, back around 2015 — or a little earlier — the last developer of my BBS software -- Michael Alyn Miller -- made a huge departure from the Pascal-based framework which was used to make games -- meaning externals -- for Hermes II, when he created a development system for externals -- called External Development System -- which is based on Jython, and not on Pascal. He then released a new version of Hermes II, which utilizes this then-new Jython framework.

The primary reason why he did this was to simplify the process of creating externals, so that SysOps who use his BBS software, can more easily create externals themselves for their own Hermes II BBSes, without all of the heavy coding and compilation work involved when using Pascal.

To show and teach SysOps how to create their own BBS externals with Python/Jython, he created an open source version of the Leech game, so that SysOps could learn from his code, which uses a lot of different functions and methods from the Jython development environment.

His Jython version of Leech in fact includes a number of class files, which after some online research, I figured out how to open with an app I found on the web. Upon opening these class files, I can see all of the imports he has made from python.org, all of the strings he has made, function names he has created, etc.

For those of you here who may have experience with this stuff, you will probably find all of this very easy to understand. However, I am not a programmer of Pascal, Python, Jython, C or anything else. Thus, I have struggled since my journey began about a week ago, and a lot of it is still Greek to me.

But, trying my best to understand Michael's coding examples, and more recently getting some help from ChatGPT — which is blowing my mind — I have made considerable progress for a 70-year-old n00b such as myself.

I now have the entry point for my game module set up in the main.py file, which consists of six ANSI screens which serve as the welcome and backstory for my game.

I also have the framework for the main menu, which currently has 5 or 6 working menu commands. I haven’t even begun working on the real meat of the game yet.

This leads us to my current problem. In the storyline for my game, I am including an option on the main menu where the game’s users can go to a spiritual retreat to relax from work. It is a place for spiritual inspiration.

If the game user types in the key command for the retreat, they will be able to randomly display, as many times as they want, quotes taken from the Bible, which are all stored in a text file in the “strings” folder, which is inside of the “resources” folder. This text file contains over 3,000 verses and verse sets from the KJV Bible, which I have personally compiled since 2002.

The coding structure for all of this has already been added to the main.py module, thanks to the Leech coding example, and to a lot of help from ChatGPT.

Now here is the problem — and I have seen through online research, that others have encountered this same problem too.

With all of this code in place, my game module is unable to load within my BBS environment, because the Java/Jython components are unable to open and read the text file which contains the aforementioned 3,000+ strings,.

The error output is stating the following. I have obfuscated the actual path for reasons of security:

Traceback (innermost last):
File "/Macintosh HD/Applications/BBS Soft/BBS Files/Doors/MyGame/main.py", line 305, in ?
File "/Macintosh HD/Applications/BBS Soft/BBS Files/Doors/MyGame//main.py", line 264, in main
File "/Macintosh HD/Applications/BBS Soft/BBS Files/Doors/MyGame//main.py", line 96, in read_quotes

java.lang.SecurityException: java.lang.SecurityException: not allowed to read resources/strings/QuotesFile.txt

A runtimeException occurred.

So the problem is that I have absolutely no idea how to give — I assume main.py — the permissions it needs to read the “QuotesFile.txt” file. It knows exactly where to find the file, and sees it, but it doesn't have permission to open it, or Java doesn't have permission, or Jython. I am really not sure which is trying to open the file. If someone can explain to me exactly how to do this -- that is, provide the needed permissions -- then hopefully, my game module will load again, and I will be able to continue working on it.

Please note that this is all happening in a Mac OS 9.2.2 environment, which is made possible by running the Qemu PPC emulator, which runs inside of macOS Sonoma 14.4.1, on my 2019 5K iMac.

So, if anyone knows the solution to this problem, and can explain it to me in layman’s terms, I wold be most appreciative.

So there you have it.
Kind regards,

Bill Kochman
 

Muz_

Member
Hi there,

I don’t have tons of experience in jython but I might be able to give you a bit of help with getting your app to launch.

Something I would test If it is not to much hassle for you is try to run it under Mac OS X you can launch a virtual machine with Mac OS X and try to run it. If you get the same lack of permission error then try to run the app from the terminal using ‘sudo’
You can type ‘sudo bash <path to your app>’ and it should launch and bypass permissions if this fixes it then tell me and we can try to work out how to get this to work under Mac OS 9
 

Hardcore SysOp

Well-known member
Hello Muz. Thanks for your offer to help. To clarify, my module will run within Hermes, IF I were to remove the various functions which make the call to the text file in question. As I said above, with those functions removed, I can easily enter the module, go through the six or so welcome and backstory intro ANSI screens, arrive at the main menu, and use a number of different commands on the Main Menu. This all works and is very stable. But trying to get the module to open the text file is simply a no-go due to the permission errors shown above. As I noted in one of my last sentences above, all of this -- Mac OS 9, Hermes II and my module do in fact run inside a virtual PPC environment created by the Qemu emulator. Qemu is an emulator, just like Basilisk II and SheepShaver.

Mind you, there is no jar file with any of this. It is all just a number of text files which form the Python/Jython module. So how would I even get it to run on the Sonoma side? I do have Python 3.12.2 -- I believe -- installed on the Sonoma side.
 

Hardcore SysOp

Well-known member
Just wanted to give you an update. I suspected that this would fail, because Python 2 is so old compared to the new features, functions and code changes which are found in Python 3, but I decided to give it a try anyway. So, I navigated to where I placed a copy of my module's files on the Sonoma side, and then I ran "python3 main.py". Sure enough, it failed with the following error:

except Exception, e:
^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized

So, I figured I just need to install the last version of Python 2, and maybe then I can run the module in the Terminal.

Ha! Sure! Right! Homebrew refused, and insisted that I install Python 3.7 instead. So, I went online, did a bit of quick research, and discovered pyenv, which I then proceeded to install via homebrew.

Once that was done, pyenv gave me a long list of python versions I could install. So, I chose the last version of version 2, which happens to be 2.7.18, and I installed that.

After that, the tutorial I found explained how to make 2.7.18 the global/active version of Python running on my system, which I did.

But then I ran into a problem. The tutorial explained how to use pyenv to create a virtual environment where I could run 2.7.18. However, when I run the command "pyenv virtualenv 2.7.18 myenv", it says that there is no command such as virtualenv.

So, I installed virtualenv with homebrew. Everything should be great now, right? NOPE! When I ran "pyenv virtualenv 2.7.18 myenv", the Terminal complains that there is no such command as virtualenv, even though it also confirmed upon my request, that virtualenv is in fact installed at usr/local/bin.

So I tried running "So I tried "sudo pyenv virtualenv 2.7.18 myenv" and still got the same response that there is no such command as virtualenv. So now what?

Regarding your suggestion to use sudo bash, when I navigated to the folder where main.py is located, and ran that command, it tried to launch xquartz -- the latest version of which I do have installed -- but then it just hung and did nothing.
 

Hardcore SysOp

Well-known member
Here's another update since posting my previous message. So I discovered a few hours ago that Python 3 actually comes with a version 2 to version 3 converter called 2to3, which you run in your Terminal app. You just type 2to3, point to your Python 2 .py file you want to update to Python 3, add a few options, or leave as is, and run it. Without any options, it will convert the file to Python 3, and mark the places in the file where it made changes. You then just copy and paste all the text from the Terminal screen into a new text document, and make the changes that it suggests, and remove your old code. Or, if you want to have it automatically convert the .py file, just add a -w to the command line, and it will make a backup of your original file first on your hard drive, and then convert the file in-document.

So I thought, "Cool! Sounds easy! I wonder if Hermes II and the Jython 2 runtime environment in Hermes will let me run the module if I update main.py to Python 3?" Ha! The joke was on me. Right from the start, from one of the functions that is located near the top of the main.py file, it threw me an exception, because I had slightly changed the format of the function from version 2 to version 3. So it was a no go.

Sadly, there is no Jython 3.0 yet. It has been stuck at 2.7 for years, which means you are stuck with running Python 2.7 in order to maintain compatibility.
 

Muz_

Member
Hi there,

As I have already mentioned I am not to aware of jython but like you said the issue is probably the old version of python/jython. Could you use qemu to emulate Mac OS 10.3 or something that will support these old versions of python I can test this if you wish to help save the time. I can just test if I can get jython and python on Mac OS 10.3 or 10.4. If this works then maybe you will be able to launch your app using sudo to give it superuser permissions, this way we don’t have to use conversion or installing legacy versions of python on an unsupported system. I will try to install this on my old iMac and tell you if I can get jython to work.

Thanks
 

Hardcore SysOp

Well-known member
Hello again, Muz. Okay, maybe I am missing something here. But exactly what is your goal in doing this? The Jython installation that I use on my BBS is a specially designed version of Jython which is compatible with my BBS software and its API. Furthermore, it is only compatible with Python 2.

Regarding permissions, while it doesn't seem possible to adjust the permissions of individual files on Mac OS 9, I have figured out how to adjust the permissions of folders on Mac OS 9, and even do it recursively, so that all enclosed subfolders and files are given the very same permissions. Despite doing this, and double-checking the path to the file in question, I have also tried manipulating the contents of the file in a variety of ways, such as by eliminating all lines consisting of x number of characters or longer, escaping quote marks, removing quote marks entirely, zapping the gremlins, etc. Nothing I have done has prevented the SecurityException. There is something that Jython doesn't like about the file which does not meet hits security parameters. I have no idea what it is. Until I figure it out, my game module has reache a dead end, sad to say.
 

Muz_

Member
Hello,

What I was trying to do was see if jython could run on Mac OS X because you were having an issue with running jython in the latest version of Mac OS. But as you are running a custom version of jython then running on anything other than the custom version then It won’t work at all so that is why it didn’t work on Mac OS sonoma. I’ll try to work out how to get permissions on Mac OS 9.
 

Hardcore SysOp

Well-known member
Hi again Muz. Thanks for trying to help out. To be clear, the issue is NOT that Jython does not run within my BBS environment. It does in fact run, as otherwise, the Leech game would not work at all, and even my own game would not work. Both do in fact work. The only reason why my game stopped working, is because I introduced the code where it must open the text file in the "strings" folder which contains all of the quotes.

After conducting some further testing, I have determined that something else is going on. There is some security parameter somewhere which is preventing the current code from opening any text file anywhere within this module's folder.

The reason why I know this to be true, is because I created some additional text files containing only a few short sentences, and I placed them in the "strings" folder, as well as in the "text" folder.

Upon doing so, I changed one line of code in my main.py module, so that the path points to the new text file that I created. In every case, whether in the "strings" folder, or in the "text", the same SecurityException error is thrown, and the code cannot open the file, no matter how small it is.

So again, some security parameter somewhere is causing this to happen. I just don't know where it is found, and much less how to change it. The developer of Hermes II and the Jython-based "External Development System" which he created, would surely know the answer. However, as I said, I have not heard from him in a good month. I don't know if my emails are suddenly going to his junk or spam folder or what, but it is very frustrating.
 

Hardcore SysOp

Well-known member
As I believe I mentioned earlier, there are over 3,400 lines in the quote file, and they are NOT just single sentences. They are entire Bible verses, or groups of Bible verses. If I were to add them all to the main.py file, it would quickly grow to over 1 MB in size. I would be concerned with how long the game would take to load when a user enters it, plus the amount of memory it would require to do so.

I could whittle the number of verses down considerably, but then I would still need help with implementing the code differently, so that it randomly selects one from within the main.py file, instead of from a separate text file in the "text" folder, which is really the ideal way to go, if the darn thing would only work proplerly without the Java SecurityException occurring.

However, at the same time, at this point, not getting this to work has brought the development of that game -- called "Space Race: Mission to Mars" -- to a complete halt, which obviously has me rather bummed out.

Meanwhile, I got an idea for a new game, now called "Name That Capital". I started working on it yesterday. Today I spent hours and hours working on it with ChatGPT. The module is not doing what it is suppose to with regards to printing out four multiple choice responses. It prints them out, but sometimes it will print out one or two cities twice, or assign two of the four cities the letter A, or even ask two questions instead of one.

Over a period of several hours, ChatGPT gave me 23 different code variations to try, and NONE of them got it right. Furthermore, ChatGPT kept using some of the same modules which I repeatedly told it NOT to use, because the version of Jython which comes with Hermes is so old -- it's 2.1 -- that it does not recognize certain modules, or else it does not recognize certain attributes which are associated with certain modules.

That is one of the most frustrating things, that the code is so old, it takes a lot of time and trial and error to discover which modules and attributes are compatible with Hermes and Jython 2.1, and which are not.

Anyway, I have lowered the security level on both games in case some of you who are experienced with Jython and Python want to take a look at them to see how far I have gotten. I am hoping that someone, or several someones, will take a serious interest, and help me to finish these two modules, because I do not have the knowledge or experience to finish them alone.

"Space Race: Mission to Mars!" will play up to the Main Menu where you can look at a few things, but the meat of the game hasn't even been written yet. With "Name That Capital", if you type P to play, you will see the error that occurs, and then it will quit you back to the BBS.
 

Hardcore SysOp

Well-known member
You could do that. Is the quotes txt in the same folder as the py file.
No, the quotes file is in the "text" folder, along with my ANSI screens and such. And that's been the problem all along, Something is causing a Java SecurityException regardless of how I name the file, and regardless of which folder I place it in. And it is NOT just the quotes file. With the current code, no matter how small the text file, or where it is placed, the SecurityException is thrown, and I have no idea where the security restrictions are even set, or how to change them.
 

Hardcore SysOp

Well-known member
Hi there,

Are you able to access the other things in the folder?
Sorry for the late response, Muz_, but I was having Internet troubles the past few days. Anyway, with all of the modules I have been working on lately, I have had no problem accessing the Main Menu and other ANSI screens which are stored in the "text" folder of each of my modules. It is just when I try to open the text file containing the 3,400+ Bible quotes that the Java security error is thrown.

As I believe I mentioned earlier, I determined that the security exception has nothing to do with the size of the file, because even when I create a file which contains only ten quotes, the security exception still occurs. I had considered that maybe it had something to do with the length of each quote, being as many are well beyond 80 characters. However, even when I only include quotes that are under 80 characters, the security exception still occurs. Lastly, I thought that perhaps the security exception might be caused by the thousands of quotes being prefixed and suffixed by a quote mark. However, even when I escaped them, or removed them altogether, it had no bearing on the security exception. So the end result is that Jython is still unable to open the file, and I have no idea why.

Unless this is resolved soon, I may have no choice but to greatly reduce the number of quotes I include in the "Retreat" section of the game, and then include them in the main.py file itself, which, as I said earlier, will bloat the file size considerably.
 

Muz_

Member
Hi there,

Can I just verify that you can access all of the files that are in the texts folder?
You were saying that it could be to do with length so if you make a new file in the directory can you access it?
 

Hardcore SysOp

Well-known member
Actually, Muz, I finally abandoned that approach, because no matter what I did, I kept getting the SecurityException, and no one had a clue regarding how to resolve it. Then a fellow on one of the Python forums suggested a different approach whereby I converted the list of Bible verses into a string and save it as a python file. He wrote a function which would result in one verse being randomly picked from the file.

However, when I tried it out a bit ago, I ran into another wall, because as you may know, in the Classic Mac environment, text files are limited to 32K in size. Well, the Bible quotes file is 740K, even after whittling it down in size. At that rate, I would have divide the one file into 25 different files, each about 30K in size in order to be on the safe side.

After that, I would have somehow alter the function that he wrote for me, so that it could first randomly select one of the 25 files containing Bible quotes, and then randomly select one verse that is found in that particular file. I imagine that there is probably some easy way to implement such a method, but I don't know how to do it myself.
 

Muz_

Member
Hi there,

Hopefully this new approach will work out better.

What you can probably do is define the different files at the start and then use a random number generator to pick the file and then repeat that in the file to randomly pick the quote.

As I am assuming you are able to access the file and the strings inside of it.

Hopefully we can finally fix this!
 
Top