Authentication Error when using Flask to connect to ParseServer
<p>What I am trying to achieve is pretty simple.</p>

<p>I want to use Flask to create a web app that connects to a remote Server via API calls (specifically ParseServer).
I am using a third-party library to achieve this and everything works perfectly when I am running my code in a stand-alone script. But when I add my code into the Flask I suddenly can't authenticate with the Server</p>

<blockquote>
  <p>Or to be more precise I get an 'unauthorized' error when executing an API call. </p>
</blockquote>

<p>It seems to me that in Flask, the registration method used by the APi library is not remembered.</p>

<p>I tried many things of putting the registration and initialization code in different places in Flask, nothing worked. </p>

<p>I asked a similar question in the Github of the <a href="https://github.com/milesrichardson/ParsePy/issues/147" rel="nofollow">Library</a> with no help. </p>

<p>So I guess I have <strong>two questions</strong> that could help me solve this</p>

<p>1) Where should I put a registration method and import of the files from this library?
&amp;</p>

<p>2) What can I do to identify the issue specifically, eg. to know precisely what's wrong?</p>

<p>Here's some code</p>

<p>The Flask code is here</p>

<pre><code>@app.route('/parseinsert')
def run_parse_db_insert():
    """The method for testing implementation and design of the Parse Db
    """
    pc = ParseCommunication()
    print(pc.get_all_names_rating_table())
    return 'done'
</code></pre>

<p>The ParseCommunication is my Class that deals with Parse. If I run ParseCommunication from that script, with the same code as above in the <strong>main</strong> part, everything works perfectly.</p>

<p>I run the Flask app with dev_appserver.py from Google App Engine.</p>

<p>My folder structure </p>

<pre><code>/parseTest
  /aplication
   views.py
  app.yaml
  run.py
</code></pre>

<p>My run.py code</p>

<pre><code>import os
import sys
sys.path.insert(1, os.path.join(os.path.abspath('.'), 'lib'))
sys.path.insert(1, os.path.join(os.path.abspath('.'), 'application'))
import aplication
</code></pre>

<p>Let me know what else I could provide to help out.</p>

<p>Thank you in Advance</p>

<p>EDIT:</p>

<p>A stack trace as requested. 
It's mostly related to the library (from what I can say?)</p>

<pre><code>ERROR    2016-09-28 06:45:50,271 app.py:1587] Exception on /parseinsert [GET]
Traceback (most recent call last):
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/theshade/Devel/ParseBabynames/parseTest/aplication/views.py", line 34, in run_parse_db_insert
    name = pc.get_user('testuser1')
  File "/home/theshade/Devel/ParseBabynames/parseTest/aplication/parseCommunication.py", line 260, in get_user
    return User.Query.get(username=uname)
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 58, in get
    return self.filter(**kw).get()
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 150, in get
    results = self._fetch()
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 117, in _fetch
    return self._manager._fetch(**options)
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 41, in _fetch
    return [klass(**it) for it in klass.GET(uri, **kw).get('results')]
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/connection.py", line 108, in GET
    return cls.execute(uri, 'GET', **kw)
  File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/connection.py", line 102, in execute
    raise exc(e.read())
ResourceRequestLoginRequired: {"error":"unauthorized"}
</code></pre>

<p>Parse requires keys and env variables.  Check this line:</p>

<p><code>API_ROOT = os.environ.get('PARSE_API_ROOT') or 'https://api.parse.com/1'</code></p>

<p>Your error is in line 102 at:</p>

<p><code>https://github.com/milesrichardson/ParsePy/blob/master/parse_rest/connection.py</code></p>

<p>Before you can parse, you need to register:</p>

<pre><code>from parse_rest.connection import register

APPLICATION_ID = '...'
REST_API_KEY = '...'
MASTER_KEY = '...'

register(APPLICATION_ID, REST_API_KEY, master_key=MASTER_KEY)
</code></pre>

python google-app-engine parse.com flask parse-server