我执行代码时遇到以下错误:
An error occurred: <HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json returned "Insufficient Permission">
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import httplib2
import os
from httplib2 import Http
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
#SCOPES = 'https://www.googleapis.com/'
SCOPES = 'https://www.googleapis.com/auth/gmail.compose'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Gmail API Quickstart'
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pyodbc打印前10行.我知道如何使用以下内容获取第一条记录:
row = cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)
我尝试将其更改为:
row = cursor.fetchten()
Run Code Online (Sandbox Code Playgroud)
但这没用.还有什么我可以做的吗?
我想将我在dash中制作的网站导出为静态PDF.这是我网站的代码(它只是一个包含3列的图表):
import dash
import dash_core_components as dcc
import dash_html_components as html
import pdfkit
from flask import Flask, render_template, make_response
app = dash.Dash()
app.layout = html.Div(
className="three columns",
children=html.Div([
dcc.Graph(
id='right-top-graph',
figure={
'data': [{
'x': [1, 2, 3],
'y': [3, 1, 2],
'type': 'bar'
}],
'layout': {
'height': 400,
'margin': {'l': 10, 'b': 20, 't': 0, 'r': 0}
}
}
),
])
)
app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})
if __name__ == '__main__':
app.run_server(debug=True)
Run Code Online (Sandbox Code Playgroud)
我尝试使用pdfkit将此代码添加到我的脚本中,但它不起作用(收到一个错误,告诉我render_template()需要1个位置参数但是给出了2个):
rendered = render_template('pdf_template.html',app)
pdf = pdfkit.from_string(rendered, False)
response …Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的gmail api代码中调用,以便我可以创建草稿,但我无法弄清楚从哪里获得"授权的Gmail API服务实例".这是我的代码:
def CreateDraft(service, user_id, message_body):
CreateDraft('SERVICE THING NEEDS TO BE HERE','me','thisisbody')
"""Create and insert a draft email. Print the returned draft's message and id.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
message_body: The body of the email message, including headers.
Returns:
Draft object, including draft id and message meta data.
"""
try:
message = {'message': message_body}
draft = service.users().drafts().create(userId=user_id, body=message).execute()
print 'Draft …Run Code Online (Sandbox Code Playgroud) 我试图从facebook页面中提取一些产品的数据并将其全部转储到文本文件中,但我发现该文件会一直覆盖数据.我不确定这是一个分页问题还是我必须制作几个文件.
这是我的代码:
#Modules
import requests
import facebook
import json
def some_action(post):
print posts['data']
print post['created_time']
#Token
access_token = 'INSERT ACCESS TOKEN'
user = 'walkers'
#Posts
graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts')
#Write
while True:
posts = requests.get(posts['paging']['next']).json()
#print posts
with open('test121.txt', 'w') as outfile:
json.dump(posts, outfile)
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
我想阻止用户按下“提交”按钮 30 秒,在他们将它推送到下面的脚本中之后。我该怎么做呢?这是我的代码目前的样子:
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Input(id='my-id', value='initial value', type="text"),
html.Button('Submit', id='button'),
html.Div(id='my-div')
])
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input('button', 'n_clicks')],
state=[State(component_id='my-id', component_property='value')]
)
def update_output_div(n_clicks, input_value):
return 'You\'ve entered "{}" and clicked {} times'.format(input_value, n_clicks)
if __name__ == '__main__':
app.run_server()
Run Code Online (Sandbox Code Playgroud)
有谁知道我如何阻止用户按下按钮 30 秒?
预先感谢。
编辑 15/08/2018 9:30AM GMT 对 stevepastelan 的回应:
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的网站中插入一个用 Flask 编写的条形图。这是我的 app.py 的样子:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html', title="Mainpage")
if __name__=='__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
这是我的条形图的样子(chart.py):
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
],
}
) …Run Code Online (Sandbox Code Playgroud) 我已将我的requirementst.txt 上传到dag 并在创建我的Airflow 环境时引用它。这是我的requirements.txt 的样子:
apache-airflow==1.10.12
oauth2client==4.1.3
google-api-python-client==2.2.0
Flask-AppBuilder==2.3.3
boto3==1.17.59
Run Code Online (Sandbox Code Playgroud)
但是,我在气流环境中不断收到“没有名为 oauthclient 的模块”错误。如何检查 oauthclient 是否已实际安装或者 Airflow 是否未正确读取我的 requests.txt 文件?
提前致谢。
有没有办法Tweepy通过Twitter手柄或Twitter ID 提取实时推文?
我尝试过使用Twitter Streaming API但我只能通过关键字过滤推文:
import tweepy
import json
# Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Variables that contains the user credentials to access Twitter API
access_token = "INSERT ACCESS TOKEN"
access_token_secret = "INSERT ACCESS TOKEN SECRET"
consumer_key = "INSERT CONSUMER KEY"
consumer_secret = "INSERT CONSUMER SECRET"
# This is a basic listener that just prints received tweets to stdout.
class …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用循环打印图表。数据在一个列表中。这是我的代码当前的样子(我在 for 循环中收到语法错误):
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
dfs = [pd.DataFrame({"xaxis":["thing","otherthing","anotherthing"],"yaxis":[64,14,62]}),pd.DataFrame({"xaxis":["newthing","newotherthing","newanotherthing"],"yaxis":[344,554,112]})]
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
g = 0
app.layout = html.Div(children=[
for df in dfs:
dcc.Graph(id='example-graph'+str(g),figure={'data': [go.Bar(x=df['xaxis'],y=df[("yaxis")],name="yaxis")]})
]
g = g + 1)
if __name__ == '__main__':
app.run_server(debug=True)
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
提前致谢。
编辑 08/03/19:我知道我可以在下面的两个图表中手动编码,但我希望将其放入循环中,因为将来我可能会在一页上显示 2 个以上的图表。
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
df1 …Run Code Online (Sandbox Code Playgroud)