5

THE QUESTION: How do I get the game to run requests.post to post url?

Basically, I am currently working on a project where the choices during the game can be sent to a website I've made, so that I can track what kind of choices the player has made. The website is complete, and I've tested it with a separate python programme, and it works perfectly fine, using two lines of code below:

import requests
con = requests.post("http://localhost:8080/update?/checkingChL")

This will trigger my website's database to change, which will be clearly displayed on the website, so the code works perfectly fine if I use a separate python file. But it seems like Ren'Py doesn't really take it as well as I hoped...

Things I've done: Attempt 1: Downloading the Python modules, as shown here - https://www.renpy.org/doc/html/python.htm

After installing the requests, I've launched the project from Ren'Py and turned the developer console on, and typed:

import requests

But the response I've got was:

ImportError: No module named cgi

So that was no go. As mentioned earlier, I'm still new to Python, so I did some Google search and tried the next attempt...

Attempt 2: Install renpy-requests, as shown here - https://github.com/renpytom/renpy-requests

With the fresh version of the game before attempt 1, I've downloaded the files and did exactly as told in the instructions. This time I've got further than the last time:

import requests
con = requests.post("http://localhost:8080/update?/checkingChL")
LookUpError: unknown encoding:idna

Again, as you can see, the error continued.

I've tried to import cgi and encodings onto the game, but no luck either... :(

I ignored the error message and stuck the code anyway to the game, and when it was on the right moment to trigger.... Only to find that nothing happened to the website at all...

Clearly, there is something missing from my game, but I am out of ideas now...

Erik Godard
  • 5,930
  • 6
  • 30
  • 33
Eric Song
  • 51
  • 2

1 Answers1

1

I'm not sure Requests module is fully supported by Ren'Py. If you're not sending sensitive information, you could use it though.

Here's a link for the github example using requests created by Tom, Re'nPy's creator. https://github.com/renpytom/renpy-requests

I use urllib and urlib2 on my game.

import urllib
import urllib2

url = "http://........."
opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
data = urllib.urlencode({'name' : playerName,'score' : playerScore})
userList = str(opener.open(url, data=data).read())

Edit 11/21/2021: the module Requests is now included in Ren'Py by default.

Saiffyros
  • 66
  • 6