0

I am trying to deploy my python code (main.py) on Google cloud shell and no errors are seen, however I get a NGINX 502 Gateway error when I try to browse my webpage.

Here are few more finding based on my troubleshooting if that helps

  1. The problem happens only when I try to call Users.py file from main.py on my cloud shell
import datetime
import Users
  1. Users.py file is residing in the same directory as main.py
  2. The code runs perfectly fine on my Pycharm env
  3. The moment I comment out import Users- the error is gone. I am able to browse through my webpage

let me know if you need any more information..

thanks

  • 1. have you checked nginx logs 2. very possibly due to [PATH](https://docs.python.org/3/using/cmdline.html) not set. – Lei Yang Jan 17 '22 at 06:40
  • sorry, bit new to this area at the moment..any help how should I be checking the logs? or how to set the path ?.. I am going thru the link – Jaideep Banerjee Jan 17 '22 at 06:43
  • how about adding the two lines at the top: `import sys,os sys.path.append(os.getcwd())` – Lei Yang Jan 17 '22 at 06:50
  • same error after adding – Jaideep Banerjee Jan 17 '22 at 06:58
  • what's the output if you not import, but run `import os print(os.path.isfile('Users.py'))` – Lei Yang Jan 17 '22 at 07:14
  • i did that..found the path..it is the 1st 2 directory. I modified my code to include the entire path 'sys.path.append("home/banerjee_jaideep/cloudshell_open/github_jban1_my-projects/Jaidemo1")' and then `import Users` . Couple of observation. On cloud shell when I run it as `Run Python File in Terminal` .. it perfectly picks data from Users.py and does the job but when I try deploying the code on my G-App Engine ..it runs fine but while trying to browse the webpage I get the 502 error – Jaideep Banerjee Jan 17 '22 at 08:07
  • do you mean now code is working? – Lei Yang Jan 17 '22 at 08:10
  • the code is working (probably always worked) when I ran it on the Python Terminal in cloud shell but the it is not working when I try to deploy it on my App engine.. – Jaideep Banerjee Jan 17 '22 at 08:17
  • I found the problem area. The issue is not with Python code. The issue is App engine does not allow pymongo to run. The solution is presented here - https://stackoverflow.com/questions/4263395/any-one-tried-mongodb-on-google-app-engine. I was able to connect and deploy my Users.py file as long as it was not using Pymongo – Jaideep Banerjee Jan 17 '22 at 10:32
  • Are you running MongoDB on App Engine Standard or rather connecting to MongoDB which may be hosted elsewhere? I want to know how you are connecting App Engine with pymongo as you are claiming the issue you are facing is due to " App engine does not allow pymongo". The stack threads you are referring to are old. So we might as well be sure before concluding that its a limitation on App Engine side. Would like more insights on your architecture. – Priyashree Bhadra Jan 18 '22 at 07:32
  • 1
    Also, please post the error message you would be receiving on the server side, along with minimal reproducible code. – Gourav B Jan 18 '22 at 07:38
  • Hi Priya, sorry for the late response, I spent yesterday the whole day just to figure out what you wrote :-(. Yes you are right. So I progressed a bit 1) I created a VM (minimal cost) on my compute engine and installed mongoDB on it. Works perfectly fine. 2) Now I need to follow Sebastian's suggestion here (https://stackoverflow.com/questions/4263395/any-one-tried-mongodb-on-google-app-engine) and connect my GAE and GCE to run my application. 3) The other challenge now I am facing is my MongoDB installed on the VM (on Ubuntu machine) I need the GUI for that (Mongo Compass) but couldn't figure – Jaideep Banerjee Jan 19 '22 at 01:22
  • Hi Gourav, the server side (on App engine) error clearly showed App engine not able to recognise Pymongo..that's when I figured out App engine does not support Pymongo. On the contrary if we host our application on heroku - I do not face any trouble at all as long as the firewall rules are 0.0.0.0/0. MongoDB sweetly connects both my local Pycharm as well the as application code hosted on heroku :-( – Jaideep Banerjee Jan 19 '22 at 01:26
  • @JaideepBanerjee can you share the error logs that showed App Engine not able to recognise pymongo? – Priyashree Bhadra Jan 19 '22 at 05:20
  • @JaideepBanerjee For your GUI MongoDB Compass, here is a [guide](https://www.digitalocean.com/community/tutorials/how-to-use-mongodb-compass) to connect your mondoDB server on GCE VM with MongoDB Compass. – Priyashree Bhadra Jan 19 '22 at 05:57
  • Priya thanks for the link ..i did see it but mongodb compass will be the GUI only if your mongo is hosted on your local machine not on a cloud server..of course possible but not straightforward. I have now given up on GCP and hosted my application seamlessly on Heroku in less than 1 hour, all at no cost especially when i am doing a POC and building an entire application..Heroku amazing at least fir my case but thanks everyone for your help – Jaideep Banerjee Jan 20 '22 at 06:34
  • You most probably missed a [configuration step](https://cloud.google.com/appengine/docs/standard/python3/connecting-vpc) – Gourav B Jan 20 '22 at 17:58
  • i did add a serverless VPC as in this document..this VPC has my GCE which has the Mongodb .. Now the question is how to make my application on GAE interact with MongDB. By the way serverless VPC also comes with a cost (min 12$ per month..based on usage)..i gave up. Heroku way easier but thanks for assisting – Jaideep Banerjee Jan 22 '22 at 06:08
  • @JaideepBanerjee Choosing Heroku over GCP for pricing/ any other reasons is completely your choice. I just want to let you know that the set up is possible in GCP as well. First of all, you haven't told me yet whether you are using GAE Standard or Flex? If you are using Flex, you should be able to connect to the db using the API through both internal & external IPs. For GAE Standard, you have to make certain arrangements, listed in this [stackoverflow thread](https://stackoverflow.com/a/46493440/15803365) – Priyashree Bhadra Jan 24 '22 at 07:10
  • Please file a [support case with GCP](https://console.cloud.google.com/support). They will tell you exactly what part of the setup is missing, we can only guess. – Gourav B Feb 03 '22 at 13:25

0 Answers0