如何在AWS Elastic Beanstalk中使用Plotly Python SDK
我一直在尝试安装Plot.ly Python SDK,我已将其包含在requirements.txt中,但仍然失败,在调用Flask提供的页面时,我收到一个页面未找到错误。Plot.ly的问题在于它需要安装凭据:如何在AWS Elastic Beanstalk中使用Plotly Python SDK,python,amazon-web-services,flask,amazon-elastic-beanstalk,plotly,Python,Amazon Web Services,Flask,Amazon Elastic Beanstalk,Plotly,我一直在尝试安装Plot.ly Python SDK,我已将其包含在requirements.txt中,但仍然失败,在调用Flask提供的页面时,我收到一个页面未找到错误。Plot.ly的问题在于它需要安装凭据: import plotly plotly.tools.set_credentials_file(username='SomeDemoAccount', api_key='SomeAPIKey') 这不会作为代码运行,也不会从控制台中的ssh运行,因为实例没有访问~/.plotly/
import plotly
plotly.tools.set_credentials_file(username='SomeDemoAccount', api_key='SomeAPIKey')
这不会作为代码运行,也不会从控制台中的ssh运行,因为实例没有访问~/.plotly/.credentials
文件的权限,即它无法创建或访问该文件,因此对API的任何调用都将始终失败。在AWS日志中,您将看到以下错误:
Looks like you don't have 'read-write' permission to your 'home' ('~') directory or to our '~/.plotly' directory. That means plotly's python api can't setup local configuration files. No problem though! You'll just have to sign-in using 'plotly.plotly.sign_in()'. For help with that: 'help(plotly.plotly.sign_in)'.
因此,解决方案是调用plotly.plotly.sign_in()
方法,该方法在《入门指南》和API参考中都没有提到,必须使用以下参数调用:
plotly.plotly.sign_in("Your Plotly Username","Your Plotly API Key")
我通过将这些值作为EB环境属性来实现:
plotly.plotly.sign_in(os.environ['YOUR_PLOTLY_USERNAME_ENV_PROPERTY_NAME'],os.environ['YOUR_PLOTLY_API_KEY_ENV_PROPERTY_NAME'])