<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Webhook Tutorial Error in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/568162#M26618</link>
    <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jan 2022 16:37:44 GMT</pubDate>
    <dc:creator>af11</dc:creator>
    <dc:date>2022-01-04T16:37:44Z</dc:date>
    <item>
      <title>Webhook Tutorial Error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567798#M26605</link>
      <description>&lt;P&gt;I downloaded the code (&lt;A href="https://github.com/dropbox/mdwebhook" target="_blank"&gt;https://github.com/dropbox/mdwebhook&lt;/A&gt;) and am trying to make this application work on my IDE.&lt;/P&gt;&lt;P&gt;The site is up but when I press on the button to connect to Dropbox, I get this error "&lt;SPAN&gt;TypeError: 'SecureCookieSession' object cannot be interpreted as an integer".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can anyone help me solve this?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 11:06:22 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567798#M26605</guid>
      <dc:creator>af11</dc:creator>
      <dc:date>2022-01-03T11:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Webhook Tutorial Error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567873#M26608</link>
      <description>&lt;P&gt;&lt;A href="https://github.com/dropbox/mdwebhook/search?q=SecureCookieSession" target="_self"&gt;The 'mdwebhook' project doesn't contain any reference of 'SecureCookieSession'&lt;/A&gt;, so can you share the full stack trace and relevant code for context? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 15:37:10 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567873#M26608</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-01-03T15:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Webhook Tutorial Error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567884#M26609</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from hashlib import sha256
import hmac
import json
import os
import threading
import urllib.parse
from dotenv import load_dotenv

from dropbox import Dropbox, DropboxOAuth2Flow
from dropbox.files import DeletedMetadata, FolderMetadata, WriteMode
from flask import abort, Flask, redirect, render_template, Response, request, session, url_for
from markdown import markdown
import redis

load_dotenv()

redis_url = os.environ.get('REDISTOGO_URL')
redis_client = redis.from_url(redis_url, decode_responses=True)

# App key and secret from the App console (dropbox.com/developers/apps)
APP_KEY = os.environ.get('APP_KEY')
APP_SECRET = os.environ.get('APP_SECRET')

app = Flask(__name__)
app.debug = True

# A random secret used by Flask to encrypt session data cookies
app.secret_key = os.environ.get('FLASK_SECRET_KEY')

def get_url(route):
    '''Generate a proper URL, forcing HTTPS if not running locally'''
    host = urllib.parse.urlparse(request.url).hostname
    url = url_for(
        route,
        _external=True,
        _scheme='http' if host in ('127.0.0.1', 'localhost') else 'https'
    )

    return url

def get_flow():
    return DropboxOAuth2Flow(
        APP_KEY,
        APP_SECRET,
        get_url('oauth_callback'),
        session,
        'dropbox-csrf-token')

@app.route('/welcome')
def welcome():
    return render_template('welcome.html', redirect_url=get_url('oauth_callback'),
        webhook_url=get_url('webhook'), home_url=get_url('index'), app_key=APP_KEY)

@app.route('/oauth_callback')
def oauth_callback():
    '''Callback function for when the user returns from OAuth.'''

    auth_result = get_flow().finish(request.args)
    account = auth_result.account_id
    access_token = auth_result.access_token

    # Extract and store the access token for this user
    redis_client.hset('tokens', account, access_token)

    process_user(account)

    return redirect(url_for('done'))

def process_user(account):
    '''Call /files/list_folder for the given user ID and process any changes.'''

    # OAuth token for the user
    token = redis_client.hget('tokens', account)

    # cursor for the user (None the first time)
    cursor = redis_client.hget('cursors', account)

    dbx = Dropbox(token)
    has_more = True

    while has_more:
        if cursor is None:
            result = dbx.files_list_folder(path='')
        else:
            result = dbx.files_list_folder_continue(cursor)

        for entry in result.entries:
            # Ignore deleted files, folders, and non-markdown files
            if (isinstance(entry, DeletedMetadata) or
                isinstance(entry, FolderMetadata) or
                not entry.path_lower.endswith('.md')):
                continue

            # Convert to Markdown and store as &amp;lt;basename&amp;gt;.html
            _, resp = dbx.files_download(entry.path_lower)
            html = markdown(resp.content.decode("utf-8"))
            dbx.files_upload(bytes(html, encoding='utf-8'), entry.path_lower[:-3] + '.html', mode=WriteMode('overwrite'))

        # Update cursor
        cursor = result.cursor
        redis_client.hset('cursors', account, cursor)

        # Repeat only if there's more to do
        has_more = result.has_more

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/login')
def login():
    return redirect(get_flow().start())

@app.route('/done')
def done():
    return render_template('done.html')

@app.route('/webhook', methods=['GET'])
def challenge():
    '''Respond to the webhook challenge (GET request) by echoing back the challenge parameter.'''

    resp = Response(request.args.get('challenge'))
    resp.headers['Content-Type'] = 'text/plain'
    resp.headers['X-Content-Type-Options'] = 'nosniff'

    return resp

@app.route('/webhook', methods=['POST'])
def webhook():
    '''Receive a list of changed user IDs from Dropbox and process each.'''

    # Make sure this is a valid request from Dropbox
    signature = request.headers.get('X-Dropbox-Signature')
    key = bytes(APP_SECRET, encoding="ascii")
    computed_signature = hmac.new(key, request.data, sha256).hexdigest()
    if not hmac.compare_digest(signature, computed_signature):
        abort(403)

    for account in json.loads(request.data)['list_folder']['accounts']:
        # We need to respond quickly to the webhook request, so we do the
        # actual work in a separate thread. For more robustness, it's a
        # good idea to add the work to a reliable queue and process the queue
        # in a worker process.
        threading.Thread(target=process_user, args=(account,)).start()
    return ''

if __name__=='__main__':
    app.run(debug=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here is the traceback to the error:&lt;/P&gt;&lt;P&gt;TypeError&lt;/P&gt;&lt;DIV class=""&gt;&lt;P class=""&gt;TypeError: 'SecureCookieSession' object cannot be interpreted as an integer&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;Traceback&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;(most recent call last)&lt;/EM&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;UL&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;2091&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;__call__&lt;DIV class=""&gt;&lt;PRE&gt;return self.wsgi_app(environ, start_response)&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;2076&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;wsgi_app&lt;DIV class=""&gt;&lt;PRE&gt;response = self.handle_exception(e)&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;2073&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;wsgi_app&lt;DIV class=""&gt;&lt;PRE&gt;response = self.full_dispatch_request()&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;1518&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;full_dispatch_request&lt;DIV class=""&gt;&lt;PRE&gt;rv = self.handle_user_exception(e)&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;1516&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;full_dispatch_request&lt;DIV class=""&gt;&lt;PRE&gt;rv = self.dispatch_request()&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\flask\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;1502&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dispatch_request&lt;DIV class=""&gt;&lt;PRE&gt;return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\app.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;112&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;login&lt;DIV class=""&gt;&lt;PRE&gt;return redirect(get_flow().start())&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;DIV class=""&gt;File&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"C:\Users\Sari\PycharmProjects\ccc-changes\venv\Lib\site-packages\dropbox\oauth.py", line&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;440&lt;/EM&gt;, in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;start&lt;DIV class=""&gt;&lt;PRE&gt;self.session[self.csrf_token_session_key] = csrf_token&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;BLOCKQUOTE&gt;TypeError: 'SecureCookieSession' object cannot be interpreted as an integer&lt;/BLOCKQUOTE&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.&lt;P&gt;To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.&lt;/P&gt;&lt;P&gt;You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;dump()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;shows all variables in the frame&lt;/LI&gt;&lt;LI&gt;dump(obj)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dumps all that's known about the object&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 03 Jan 2022 15:50:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567884#M26609</guid>
      <dc:creator>af11</dc:creator>
      <dc:date>2022-01-03T15:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Webhook Tutorial Error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567922#M26610</link>
      <description>&lt;P&gt;Thanks, that's helpful. It looks like you're running this sample project with the latest version of the 'dropbox' package (currently v11.25.0), however this sample project was only written for an older version. Attempting to use it with the latest version will fail like this due to subsequent changes in the 'dropbox' package.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to run this sample project, you should install &lt;A href="https://github.com/dropbox/mdwebhook/blob/master/requirements.txt" target="_self"&gt;the project requirements as listed in the project here&lt;/A&gt; (which specifies 'dropbox==9.4.0'). The &lt;A href="https://github.com/dropbox/mdwebhook#running-the-sample-yourself" target="_self"&gt;instructions for the sample project&lt;/A&gt; show how to install the requirements. (You may want to use something like virtualenv though.)&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jan 2022 19:03:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/567922#M26610</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-01-03T19:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Webhook Tutorial Error</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/568162#M26618</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 16:37:44 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Webhook-Tutorial-Error/m-p/568162#M26618</guid>
      <dc:creator>af11</dc:creator>
      <dc:date>2022-01-04T16:37:44Z</dc:date>
    </item>
  </channel>
</rss>

