Renpy requests package

yozayozo

Newbie
Sep 14, 2021
18
2
I'm having a lot of trouble using requests python package inside Renpy game. How does one use it?
View attachment requestsTraceback.txt
I tried installing it with pip, installing older versions. All inside game/python-packages
Found this in the but nothing worked so far.
This is how my python-packages looks like: 1634361623266.png
Inside the game only two lines that crash the game are: 1634361441600.png , if the import is commented out the game will work.
I have made the code with a single post request and some data in regular python which works, now implementing the same code in Renpy feels like a nightmare

Does anyone have any clue how to make requests package work?
(I get the same thing when importing types from SimpleNamespace --> code line:
Code:
from types import SimpleNamespace
)

PS: provided both tracebacks for error when starting the game with requests imported and types from SimpleNamespace imported
 
Jul 22, 2019
247
369
I tried and it worked fine. Make sure you're not using python 3 to install the package. If you are than you might get an error. I tried installing using python 3.8.3 and I got the following error (though different than yours) I also use an older version of renpy though, the error could be because renpy is more geared for python 2 and the library could be using some python 3 stuff (which I just checked, it was).

1634369983799.png

But when using python 2 (2.7.18 in my case) it worked fine. If you're using something like anaconda you can setup separate environments with different python installations to make your life easier.

The same problem with SimpleNamespace. The class was introduced in python 3 so you can't use it in renpy.
 
  • Like
Reactions: yozayozo

yozayozo

Newbie
Sep 14, 2021
18
2
Uninstalled 3.8+ python and installed 2.7.18
added pip to path and installed requests for python
deleted python-packages in the game folder
installed requests via 2.7.18. python
launched the game with imported requests and it worked! Thank you!
 

yozayozo

Newbie
Sep 14, 2021
18
2
I tried and it worked fine. Make sure you're not using python 3 to install the package. If you are than you might get an error. I tried installing using python 3.8.3 and I got the following error (though different than yours) I also use an older version of renpy though, the error could be because renpy is more geared for python 2 and the library could be using some python 3 stuff (which I just checked, it was).

View attachment 1455001

But when using python 2 (2.7.18 in my case) it worked fine. If you're using something like anaconda you can setup separate environments with different python installations to make your life easier.

The same problem with SimpleNamespace. The class was introduced in python 3 so you can't use it in renpy.
bipedal_bastard I have now run on another problem.
When calling a requests.post function from withing renpy game, it crashes and gives an error:

x = requests.post(funcUrl, headers = headers, json = dataObj)
IOError: Could not find a suitable TLS CA certificate bundle, invalid path: python-packages/certifi\cacert.pem

The python-packages contains certifi/cacert.pem tho. I tried copying it to requests folder as a user suggested . But it didn't work

Did you do any additional configurations before using requests inside Renpy?
 

yozayozo

Newbie
Sep 14, 2021
18
2
if verify=False is added then we have another error and that is:

x = requests.post(funcUrl, cert=('client.crt', 'client.pem.txt'), headers = headers, json = dataObj, verify=False)
IOError: Could not find the TLS certificate file, invalid path: client.crt
 
Jul 22, 2019
247
369
bipedal_bastard I have now run on another problem.
When calling a requests.post function from withing renpy game, it crashes and gives an error:

x = requests.post(funcUrl, headers = headers, json = dataObj)
IOError: Could not find a suitable TLS CA certificate bundle, invalid path: python-packages/certifi\cacert.pem

The python-packages contains certifi/cacert.pem tho. I tried copying it to requests folder as a user suggested . But it didn't work

Did you do any additional configurations before using requests inside Renpy?
I have never actually used it. But your issue seems to be because during development, renpy seems to use the directory of where renpy is located rather than the directory of the game. So basically instead of looking for this file in "game/python-packages/certifi", its looking for it in "wherever-your-renpy-folder-is/renpy-x.x.x-sdk/python-packages/certifi". I think it does it because that's where python is installed (or atleast the installation it uses before packaging). This doesn't happen once you package the game though.

So idk, see if you can change the working directory. Use something like os.chdir() and set it to the current absolute path of the "game" folder (though be sure to remove it once you actually package the game and release it) before using the library or the quick fix is to just go to your renpy sdk folder and inside there make this directory "python-packages/certifi" and put cacert.pem in there. Like the following, it should fix it. But I think you'll run into similar issues again at some point so changing the working directory might be the better thing.

1634387791373.png
 
Last edited:

yozayozo

Newbie
Sep 14, 2021
18
2
I have never actually used it. But your issue seems to be because during development, renpy seems to use the directory of where renpy is located rather than the directory of the game. So basically instead of looking for this file in "game/python-packages/certifi", its looking for it in "wherever-your-renpy-folder-is/renpy-x.x.x-sdk/python-packages/certifi". I think it does it because that's where python is installed (or atleast the installation it uses before packaging). This doesn't happen once you package the game though.

So idk, see if you can change the working directory. Use something like os.chdir() and set it to the current absolute path of the "game" folder (though be sure to remove it once you actually package the game and release it) before using the library or the quick fix is to just go to your renpy sdk folder and inside there make this directory "python-packages/certifi" and put cacert.pem in there. Like the following, it should fix it. But I think you'll run into similar issues again at some point so changing the working directory might be the better thing.

If I build the game, the issue remains the same as the initial one

IOError: Could not find a suitable TLS CA certificate bundle, invalid path: python-packages/certifi\cacert.pem

If I add "python-packages/certifi" to sdk folder and launch without building. It gives a new but similar error.

IOError: Could not find the TLS certificate file, invalid path: client.crt

I'm slowly losing it :C it works so beautifully in regular python code
 
Jul 22, 2019
247
369
If I build the game, the issue remains the same as the initial one

IOError: Could not find a suitable TLS CA certificate bundle, invalid path: python-packages/certifi\cacert.pem

If I add "python-packages/certifi" to sdk folder and launch without building. It gives a new but similar error.

IOError: Could not find the TLS certificate file, invalid path: client.crt

I'm slowly losing it :C it works so beautifully in regular python code
Yeah using external libs in renpy is a pain in the ass I guess. But the problem stems from the directory issue.

I tried out some stuff, and I agree this is just retarded, you shouldn't have to do this, there is probably a better way but unfortunately idk. Add the following to your code before using the library

Python:
if (renpy.config.developer == True):
    os.chdir("D:/dev/renpytest/game")   # replace this with the path to your "game" folder
else:
    os.chdir(os.getcwd() + "/game")
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,226
I tried installing it with pip, installing older versions.
Ok, remove all this things, and just use the requests module that come natively with Ren'py.

And magically, all your problems will disappear.
 
  • Like
Reactions: yozayozo
Jul 22, 2019
247
369
Ok, remove all this things, and just use the requests module that come natively with Ren'py.

And magically, all your problems will disappear.
There you go lol, I knew there was probably a better way. I hadn't realized it had happened, I still had a year old version of Ren'py.

OP if the import is not working natively on your end you need to update to at least 7.4.0 or later. Anyway if in the future you do end up using some other third party libs, now you know the common issues that can arise, most of them are going to be directory related or python 2/3 related, and you can try out some of the stuff above to tackle it.
 
  • Like
Reactions: yozayozo

yozayozo

Newbie
Sep 14, 2021
18
2
Ok, remove all this things, and just use the requests module that come natively with Ren'py.

And magically, all your problems will disappear.

Wow it actually works! Thank you so much!

I don't understand why it does work though.
Before when I just imported requests the game would crash upon the start.

Is it because now i have python 2.7 and not 3.8+?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,226
Before when I just imported requests the game would crash upon the start.
There were another reason for that. I don't know which, but it's not because you imported this particular module.


Is it because now i have python 2.7 and not 3.8+?
No, because the version of Python installed on your computer do not matter, Ren'py use the interpreter that come with itself.
 
  • Like
Reactions: yozayozo