1

公式の Dropbox API を介して Dropbox にログインし、Dropbox にファイルをアップロードしようとしています。

このコードは、Dropbox にログインするために送信ボタンをクリックするようには見えません。コードは停止せず、ハングまたはフリーズするだけです。エラーが発生しないため、トレースバックはありません。

奇妙なのは、電子メールまたはパスワード (またはその両方) の入力をコメントアウトすると、送信ボタンのクリックが機能することです。

手動で Dropbox 認証リンクにアクセスして [許可] ボタンをクリックしたくありません。そこで、ブラウザーのアクションを自動化できるツール ( Splinter )を使用して、そのタスクを自動化しようとしています。

私のコードではSplinterを使用しており、ブラウザーの種類としてPhantomJSを使用しています

コードは次のとおりです。

from splinter import *
from dropbox import client, rest, session

# Initiate Dropbox API
APP_KEY = '###'
APP_SECRET = '###'
ACCESS_TYPE = 'dropbox'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
emailDropbox = '###'
passwordDropbox = '###'

request_token = sess.obtain_request_token()

urlDropbox = sess.build_authorize_url(request_token)

# Start Splinter login code
# Assumes you are not logged in to Dropbox

# Target url
print 'Target url: ', urlDropbox

browser = Browser('phantomjs')
print 'Starting browser'
print 'Visiting url'
browser.visit(urlDropbox)

# Email form
print 'Is the email form present? ', browser.is_element_present_by_id('login_email')
print 'Fill email form'
browser.find_by_id('login_email').first.fill(emailDropbox)

# Password form
print 'Is the password form present? ', browser.is_element_present_by_id('login_password')
print 'Fill password form'
browser.find_by_id('login_password').first.fill(passwordDropbox)

# Login submit button
print 'Is the submit button present?', browser.is_element_present_by_name('login_submit_dummy')

# Click submit button
print 'Attempting to click the submit button in order to login'
browser.find_by_name('login_submit_dummy').first.click()
print 'Submit button successfully clicked'

# Allow connection with Dropbox
print 'Is the "Allow" button present?', browser.is_element_present_by_id('allow_access')
browser.find_by_id('allow_access').click()
print 'The "Allow" button is successfully clicked'

# Quit the browser
browser.quit()

# The rest of the Dropbox code
# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)

client = client.DropboxClient(sess)
print "linked account:", client.account_info()

f = open('working-draft.txt')
response = client.put_file('/magnum-opus.txt', f)
print "uploaded:", response

何が問題なのか、どうすれば修正できるのか、誰かが知っていますか?

ありがとう。

4

1 に答える 1