Android应用程序在启动/导入错误时崩溃:没有名为请求的模块

时间:2017-07-07 15:39:56

标签: android python kivy

我在Windows上安装了请求,但无论如何我都运行了命令pip install requests。 我可以使用请求从服务器获取数据,所以我不知道为什么我在发布我创建的应用程序时会出现此错误here。 我不确定,但我认为这可能是导致崩溃的原因,后来会触发:

“查找失败的窗口”

java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@e668ad1 does not exist

如何解决此问题并阻止我的应用程序立即崩溃?

import requests
import json
import matplotlib.pyplot as plt
import datetime
import time
from operator import itemgetter
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App

class placeHolder():

    def getSession():
        #Access Server
        auth = requests.auth.HTTPBasicAuth('<secret>', '<secret>')
        r = requests.get('<secret>', auth=auth)
        user_info = r.json()
        r = requests.get('<secret>'.format(user_info['tanks'][0]), auth=auth)
        #print(json.loads(r.text))

        #Get the data we want
        data = []
        for i in range(len(json.loads(r.text))-5, len(json.loads(r.text))):
            important = json.loads(r.text)[i]["recorded_time"] + " " + json.loads(r.text)[i]["top_temperature"] + " " + \
                        json.loads(r.text)[i]["bottom_temperature"] + " " + json.loads(r.text)[i]["charge"]
            Data = important.split()
            data += [Data]
        return data


    def convertTime(data):
        #Need to order data so convert to unix
        for i in data:
            t = i[0] + " " + i[1]
            new_t = time.mktime(datetime.datetime.strptime(t, "%Y-%m-%d %H:%M:%S").timetuple())
            del i[0] #delete date
            del i[0] #now time is in 0th position, delete time
            i += [new_t]
        return data


    def orderTime(data):
        #Matplotlib needs the data to be ordered or it won't plot properly
        orderedData = sorted(data, key=itemgetter(3))
        return orderedData


    def plotData(dataToPlot):
        x = []
        yTop = []
        yBottom = []
        charge = []

        #Populate lists with data
        for i in dataToPlot:
            dateToStr = datetime.datetime.fromtimestamp(int(i[3])).strftime('%Y-%m-%d %H:%M:%S')
            date = datetime.datetime.strptime(dateToStr, "%Y-%m-%d %H:%M:%S")
            yTop += [i[0]] #top temp
            yBottom += [i[1]] #bottom temp
            charge += [i[2]]
            x += [date]

        #Plot Data
        ax = plt.gca()
        ax.set_ylim([0, 100])
        plt.title("Tank Data")
        plt.plot_date(x, yTop, "r-", label="Top Temp") # labels not working
        plt.plot_date(x, yBottom, "b-", label="Bottom Temp")
        plt.plot_date(x, charge, "y-",  label="Charge")
        plt.xlabel("Time")
        plt.ylabel("Temperature")
        plt.xticks(rotation=45)
        plt.subplots_adjust(left=0.12, bottom=0.20, right=0.90, top=0.88)
        plt.legend(loc="best", prop={'size':9})
        plt.grid(True, linestyle="-", linewidth=0.5)

        #plt.show() Without this it works in Kivy

    def stuff():
        #Cleaner to do this here instead of within the build function below
        sessionData = placeHolder.getSession()
        selectedData = placeHolder.convertTime(sessionData)
        toPlot = placeHolder.orderTime(selectedData)
        placeHolder.plotData(toPlot)
        box = BoxLayout()
        box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
        return box

类Tank_GraphApp(App):

def build(self):
    box = placeHolder.stuff()
    return box

if __name__== "__main__":
    Tank_GraphApp().run()

0 个答案:

没有答案