-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hi i used your repo in flask it give error "KeyError: 'userid'" #13
Comments
This is because you're missing a userid in your session. Mostly likely this is because you tried to open the app directly instead of loading it via the BigCommerce control panel. You'll want to connect the app to the BigCommerce app store by setting it up on devtools.bigcommerce.com with the correct callback and load URL, then try loading it from within BigCommerce. The readme has some details on that. |
Booker I did this. It still doesn't work. I opened it directly and through the control panel. It is generating a Internal Server Error. Can you provide documentation that better goes over this or a example? Every documentation link that I have found is broken or unrelated. |
@Johnathanrs what logs do you see server-side when you get an internal server error? |
Booker, The SSL certificate used to load resources from https://c.la4-c2-dfw.salesforceliveagent.com will be distrusted in M70. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.
I should make a note that I ran it both locally and deployed it through heroku. It works in neither stage. I also ran the PHP version, and it worked fine, so it tells me that their is a problem here specifically with the python tutorial app. |
This appears to be an error log from within the browser itself - do you have a server side error log? If you're using heroku, you can get this by causing the issue (get the server error on your screen) and then running |
2018-08-15T02:06:37.340803+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request |
I'm curious if your database is initialized - if you installed via the heroku button, this should have happened automatically. Do you see any tables in your database, and do you see a store's details in them? If you don't see any tables, try logging into the dyno (
|
No change. You are welcome to run up a trial yourself real fast or you can also have access to my accounts and see if you can get a trial working. I have nothing sensitive on them right now. |
I'm trying to spin it up locally to see if I can replicate your issue; I've only used heroku with this app in recent years because it absorbs a lot of the complexity around the installation process. :) What are your callback URLs when you're using it locally? Are you using something like ngrok for tunneling? Is your app URL env variable different from your callback URL, perhaps it's localhost? It would seem that you're getting at least this far: https://github.com/bigcommerce/hello-world-app-python-flask/blob/master/app.py#L181-L182 But by the time you get here, flask can't access the session cookie: https://github.com/bigcommerce/hello-world-app-python-flask/blob/master/app.py#L280 This could happen if the hostname changed between the callback and the index, as we wouldn't have access to the cookie. |
Yes I tried using ngrok and I changed my local variables and did a echo to verify that they were pulling correctly. I used localhost and 0.0.0.0 including different ports. I don't understand though how this would impact heroku however because I am hosting it through them. As long as the user enters in the proper API callbacks that is generated through the website, which I did and re-tried 3 times, it should go through no problem seeing how you created the heroku launch. I also verified that I was doing the process correctly through a PHP install and it worked just fine when I deployed it. I am new to Heroku but it does the installation process for you. I can understand me doing something wrong locally, but again when I deploy it through heroku, how would the this deployment become affected by any of this? |
Yeah the specific error you're seeing is flask saying "hey we couldn't find (this value) in the session cookie", probably because there was no session cookie. So now we're back to the frontend, figuring out if the cookie is available in the right place... You might try opening your app URL directly and checking for this cookie: |
This takes us back to my original post. I think you are right. I think that the flask session object is getting loaded because of this function: I think the access is getting denied because it isn't properly being generated, but I don't know enough about Oauth to recreate this on my own and see what these fields require. I tried generating this on my own and did it step-by-step through the shell and got hit with a error, but I am not sure on how to invoke this because I don't know what these fields represent. |
I tried setting my ngrok URL as my APP_URL and it works: DEBUG=True |
Internal Server Error: 'storeuserid' Is what i'm seeing when I click on your URL |
I have it set to store owner, but everything else is the same. I didn't think that would impact anything, but do you want me to adjust it to multiple users? Yes, they match the settings from heroku though. |
Multiple users shouldn't really matter. So just to confirm, you're trigger the app install flow from "my draft apps"? https://your-store-url.com/manage/marketplace/apps/my-apps/drafts and clicking install? |
Here's a problem: https://user-images.githubusercontent.com/4458906/44129351-9d081294-9ffc-11e8-92e2-5f06cdfa08e4.png You need to replace the value of APP_URL with https://secondgo.herokuapp.com Check out the instructions page here: http://secondgo.herokuapp.com/instructions (disappears when you turn off debug) |
I added the value, re-launched dynos, no change. |
In your screenshot you're just loading the URL; can you also try the install from within the store? https://your-store-url.com/manage/marketplace/apps/my-apps/drafts (replace store URL with your own, probably works best if you're already logged in) You want to be logged in as the store owner account on the store, and using the same email you use for devtools. |
Okay got you. It's working! Thank you booker! You might want to update your tutorial with the app details, I found a few other posts online that had the same error when trying to run this up. Thank you so much for your time! |
Sure, and thank you for highlighting your experience so we can improve the readme and docs! |
We've pushed some readme updates in #25 Closing. |
Hi There, I am also getting the same error while hosting the site in heroku. could you please help me out to resolve the issue. Here is my code below from common.database import Database from flask import Flask, render_template, request, session, make_response app = Flask(name) # 'main' app.secret_key='secret123' @app.route('/') @app.route('/login') @app.route('/register') @app.before_first_request @app.route('/auth/login', methods=['POST'])
@app.route('/auth/register', methods=['POST','GET'])
@app.route('/blogs/string:user_id')
@app.route('/blogs/new', methods=['POST', 'GET'])
@app.route('/posts/string:blog_id')
@app.route('/posts/new/string:blog_id', methods=['POST', 'GET'])
if name == 'main':
|
hi i setup all file in my virtual env but it return error
KeyError
KeyError: 'userid'
Traceback is
Traceback (most recent call last):
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/vrs/Flask/big-commerce/hello-world-app-python-flask/app.py", line 238, in index
user = User.query.filter_by(id=flask.session['userid']).first()
File "/home/vrs/Flask/big-commerce/lib/python2.7/site-packages/werkzeug/local.py", line 368, in
getitem = lambda x, i: x._get_current_object()[i]
KeyError: 'userid'
how can i solve this error
The text was updated successfully, but these errors were encountered: