Spotipy doesnt work with a python to apk application

Viewed 38

Hello i have been trying to build an application which list all the content of a spotify playlist using the spotipy library which communicates with the spotipy api. My programm works fine on pc but when i try to convert it with buildozer to an apk it doesnt work.I have managed to find the error using the android debug bridge with logcat function which you can find (pastebin) here. I am able to provide you with any more information you want

This is my code which works fine on pc with the pycharm editor

from time import sleep
from threading import Thread
import spotipy
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivy.uix.boxlayout import BoxLayout
from spotipy.oauth2 import SpotifyClientCredentials
kv="""

MyLayout:
<MyLayout>:
    orientation:"vertical"
    TextInput:
        id:text
    Button:
        text:"start"
        on_release: root.start()
    Label:
        text:root.Output
        
"""

class MyLayout(BoxLayout):
    Output = StringProperty()
    SPOTIPY_CLIENT_ID = "69b85ad4ba7d4efb9265321b98a775fd"
    SPOTIPY_CLIENT_SECRET = "247f5c4dd5334e94a2aa7b67c1a53366"



    def get_songs(self):
        sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=self.SPOTIPY_CLIENT_ID,
                                                                             client_secret=self.SPOTIPY_CLIENT_SECRET,
                                                                             ))
        song = sp.playlist_items(playlist_id=self.ids.text.text, offset=0)
        for item in song["items"]:
            print(item['track']['name'] + " " + item['track']['artists'][0]['name'])
            sleep(1)
            self.Output= item['track']['name'] + " " + item['track']['artists'][0]['name']
    def start(self):
        p = Thread(target=self.get_songs)
        p.start()
class MyApp(App):
    def build(self):
        return Builder.load_string(kv)

MyApp().run()

And here are the buildozer.spec requirements(the only thing i needed to change)

requirements = python3,kivy==2.1.0,spotipy,charset-normalizer,redis,requests,flask,flask-cors,urllib3,urllib3,packaging,idna

Thank you in Advance

1 Answers

I have managed to find the answer to my question. So the error is happening because there is no internet connection and the solution is to go to the buildozer.spec fille

#android.permissions = INTERNET

here and just remove the "#" and it should work just fine

Related