Jump to content
Sign in to follow this  
You need to play a total of 1 battles to post in this section.
Rukenshia

ModAPI: web.openUrl not allowing localhost?

4 comments in this topic

Recommended Posts

[TV0]
Privateer
30 posts
2,690 battles

Hi,

 

I've been trying to build a mod that makes calls to a local server. When using "web.getAllowedUrls()", it returns a list with ['127.0.0.1', 'localhost'].

 

When I make a request however, I get "None" as result of the request, implying that no handler was available to process this request internally. Did someone do this before?

 

I've tried running my server on port 1323 and port 80. If I don't pass a URL Scheme (http://), then the request does not finish at all.

 

My code:

API_VERSION = 'API_v1.0'
MOD_NAME = 'MyMod'

res = web.openUrl('http://127.0.0.1/battle') 

print('%s'%(res))

 

--> Always None

Share this post


Link to post
Share on other sites
Administrator
136 posts
15 battles

Hello
 

"Web" methods allow you to work with web resources.

Available methods:

  • web.getAllowedUrls()

This function returns a list, a list of allowed URLs.

  • web.addAllowedUrl(encodedUrl)

This function adds a special encoded URL to the list of allowed URLs. You can request a special encoded URL from MedvedevTD by private messaging him at the official game forum.

The input arguments is encodedUrl, a special encoded URL.

  • web.openUrl(url)

The method is similar to "urllib2.urlopen(url, data=None)", it allows you to open a URL from the list of allowed URLs.
The input argument is an allowed URL.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib2.html#urllib2.urlopen

  • web.urlEncode(query)

The method is similar to "urllib.urlencode(query, doseq=0)", it is used for coding a line in the format following the rules for data in queries.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib.html#urllib.urlencode

  • web.urlQuote(s, safe='/')

The method is similar to "urllib.quote(string, safe)", it replaces all special symbols by strings "%nn". Numbers, Latin characters and underscore characters, dots and hyphens are not coded. Spaces are converted into the string "%20".
The input argument is "s", it’s the line where replacements are made, "safe" is symbols that cannot be converted.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib.html#urllib.quote

 

Share this post


Link to post
Share on other sites
[TV0]
Privateer
30 posts
2,690 battles
47 minutes ago, MedvedevTD said:

Hello
 

"Web" methods allow you to work with web resources.

Available methods:

  • web.getAllowedUrls()

This function returns a list, a list of allowed URLs.

  • web.addAllowedUrl(encodedUrl)

This function adds a special encoded URL to the list of allowed URLs. You can request a special encoded URL from MedvedevTD by private messaging him at the official game forum.

The input arguments is encodedUrl, a special encoded URL.

  • web.openUrl(url)

The method is similar to "urllib2.urlopen(url, data=None)", it allows you to open a URL from the list of allowed URLs.
The input argument is an allowed URL.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib2.html#urllib2.urlopen

  • web.urlEncode(query)

The method is similar to "urllib.urlencode(query, doseq=0)", it is used for coding a line in the format following the rules for data in queries.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib.html#urllib.urlencode

  • web.urlQuote(s, safe='/')

The method is similar to "urllib.quote(string, safe)", it replaces all special symbols by strings "%nn". Numbers, Latin characters and underscore characters, dots and hyphens are not coded. Spaces are converted into the string "%20".
The input argument is "s", it’s the line where replacements are made, "safe" is symbols that cannot be converted.

You can see full documentation on this function on the official Python website here: https://docs.python.org/2/library/urllib.html#urllib.quote

 

Hi,

 

this is the URLs that I used. As described by default 127.0.0.1 and localhost are whitelisted, so I am unsure why I cannot get my request through.

 

Here my recent example to reproduce:

 

API_VERSION = 'API_v1.0'

devmenu.enable()
with open('test.log', 'w') as f:
    f.write('[WhitelistedURLTest] start\n')
    f.write('[WhitelistedURLTest] %s\n' % (web.getAllowedUrls()))
    f.write('[WhitelistedURLTest] response %s\n' %
            (web.openUrl('http://127.0.0.1')))
    f.flush()

    f.close()

 

Output:

 

[WhitelistedURLTest] start
[WhitelistedURLTest] ['127.0.0.1', 'localhost']
[WhitelistedURLTest] response None

 

The python.log did not contain any related information to these requests (no errors or anything). My server running on 127.0.0.1:80 did not receive any request.

 

Another thing I am unclear about is whether a whitelisted URL is a domain whitelisting or only for that specific path (so in this case, http://127.0.0.1/ or http://localhost/). Maybe you can shed some light on this/

 

Thank you very much for the quick initial response.

Cheers,

Share this post


Link to post
Share on other sites
Administrator
339 posts
12 battles

Hello,

Thank you for paying attention to this error, as it turned out this is. Unfortunately it's a bug of ModAPI, default allowed urls can't be open now, we'll fix it in one of the next patches. Also if you need to open different url, send me total string of it in PM.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×