Requests library in addon
#1
Hi, I want to use the requests library in an addon script. Is there a way how can I add the library in a library subfolder of my module ?

And another question I got and I couldn't find it anywhere where I searched, is there a tutorial of detailed UI components with example and ations/triggers/listeners to change the UI to another window, list item click listener etc ...

Best,
Marian
Reply
#2
requests library is in the official Kodi repo. But you can simply copy it into your addon and then add its path to Python sys.path list.

As for GUI, please explain, what you mean. Do you want to create your own UI for an addon or to interact with Kodi UI?
Reply
#3
Thank you for you reply Smile

I want to create the addon UI using kodi existing UI in the same way as other add-ons UI are created.

I will use Requests to get a list of file from CLOUD and list some content ( movies, music, photos )
Clicking on a file that is not directory ( movie, music, photo ) will stream the content using Kodi.

For requests I have downloaded the module from here: https://github.com/beenje/script.module.requests

I have placed it inside kodi/addons/script.module.requests
In my python file I import requests using the following line:

import requests

and in my xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.digistorageplayer" name="Digi Storage Player" version="1.0.0" provider-name="****">
<requires>
<import addon="script.module.pyxbmct" version="1.1.4"/>
<import addon="xbmc.python" version="2.14.0"/>
<import addon="script.module.requests" version="2.9.1"/>
</requires>
<extension point="xbmc.python.script" library="addon.py">
<provides>executable</provides>
</extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en">***</summary>
<description lang="en">***</description>
<license>GNU General Public License, v2</license>
<language></language>
<email>****</email>
</extension>
</addon>

The result is the following:

ImportError: No module named requests
Reply
#4
(2016-03-14, 09:24)marian.pavel Wrote: I want to create the addon UI using kodi existing UI in the same way as other add-ons UI are created.

Sorry, but this phrase just makes no sense for me. I understand the "I want to create the addon UI" part, but I have no idea what "using kodi existing UI in the same way as other add-ons UI are created" means. There are 3 possible ways to create addon UIs:

Content pugins can use Kodi plugin API (xbmcplugin module) to create lists of content to be played in Kodi. All you need is to create a list with necessary information and Kodi does the rest, like list displaying and event handling.

General purpose addons can create arbitrary UIs using either Window*/Control* classes or WindowXML* classes and skinned UIs. The latter approach offers more features but it is also more complicated.

So what do you really need?

Regarding the rest, without a full debug log only psychics can tell.
Reply
#5
Is there another way how to view the log file ? I am using Log Viewer for Kodi, I need to make you some screenshots because I couldn't find where are the logs of the modules saved.

About the UI, I will create the lists of content in kodi using xbmcplugin module but first I need to solve the problem with this library.
Reply
#6
http://kodi.wiki/view/Log_file/Easy
Reply
#7
http://xbmclogs.com/pgcxvbxx2

And this is my python script:

import xbmcaddon
import xbmcgui
import pyxbmct
from xml.dom import minidom
import requests
import json
import getpass


addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')

credentials = minidom.parse('credentials.xml')
itemlist = credentials.getElementsByTagName('item')
print(len(itemlist))

username = itemlist[0].attributes['value'].value
password = itemlist[1].attributes['value'].value

print(username + " " + password)

api_base = 'url'

s = requests.Session()

# get auth token

token = s.get(api_base + '/token', headers = {
'Email': username,
'Password': password
}).headers['Token']

s.headers['Authorization'] = 'Token ' + token

# get mount (Dropbox...)

mounts = s.get(api_base + '/api/v2/mounts').json()['mounts']

mount = [x for x in mounts if x['name'] == 'Cloud'][0]

print(mount['name'] + mount['id'])

# list files

files = s.get(api_base + '/api/v2/mounts/' + mount['id'] + '/files/list', params = {'path': '/'}).json()['files']

line = ""

for file in files:
line += file['name'] + "\n"

xbmcgui.Dialog().ok(addonname, line)
Reply
#8
Strangely enough "script.module.requests" is listed in the log. Check, if it is actually present in your user addon folder: C:\Users\Marian Pavel\AppData\Roaming\Kodi\userdata\addons\ and if it is enabled in the Kodi addon manager. Kodi 17 is paranoid about third-party addons and the good old trick with installing addons by simply copying them into \addons folder does not work any more without explicitly enabling those addons in Kodi settigns.
Reply
#9
The following path is available:

C:\Users\Marian Pavel\AppData\Roaming\Kodi\addons\script.module.requests-gotham

But I don't have in userdata any addons subfolder, I only have addon_data.

What I have noticed is that requests doesn't even show in kodi addon list.
Reply
#10
(2016-03-15, 14:56)marian.pavel Wrote: The following path is available:

C:\Users\Marian Pavel\AppData\Roaming\Kodi\addons\script.module.requests-gotham

It must be "script.module.requests" verbatim.

Quote:But I don't have in userdata any addons subfolder, I only have addon_data.

What I have noticed is that requests doesn't even show in kodi addon list.

Sorry for my mistake. I meant addon subfolder in Kodi user data folder. On Windows it is usually %userprofile%\Kodi\addons
Reply
#11
I don't think I've imported the addon as I should, even if the module appears in the addon directory it's not listed in kodi.
Reply
#12
(2016-03-15, 16:37)marian.pavel Wrote: I don't think I've imported the addon as I should, even if the module appears in the addon directory it's not listed in kodi.

I'm pretty sure addon modules like requests don't show up in the Kodi GUI anywhere (I didn't see requests on mine, but I know it's installed and working).
Reply
#13
I have understand, I found a solution and now It's working Smile

Thank's for the help !
Reply
#14
Hi, I am facing the same issue, can you please share what solution worked for you.
Reply
#15
I added <import addon="script.module.requests" version="2.9.1"/> in my addon.xml file
You can view my project here: https://github.com/marianpavel/plugin.vi...rageplayer
Reply

Logout Mark Read Team Forum Stats Members Help
Requests library in addon0