daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Apr 29th, 2017 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @app.route('/get_user_profile_pic', methods=['POST'])
  2. def get_user_profile_pic():
  3.     try:
  4.  
  5.         email = request.form['email']
  6.         conn = MySQLdb.connect(host='localhost', user='muscle', password='some_pass')
  7.         c = conn.cursor(MySQLdb.cursors.DictCursor)
  8.         c.execute('USE muscle2')
  9.  
  10.  
  11.         c.execute("SELECT Profile_image FROM USER WHERE Email = %s", [email])
  12.  
  13.         fetched = c.fetchone()['Profile_image']
  14.         print(fetched)
  15.  
  16.         if(not fetched):
  17.             return "User profile image not found"
  18.        
  19.         img_dir = "user_profile_pics/"
  20.         img_path = fetched
  21.         #img_path = "user_{:0>{width}}_profile_pic".format(ID,width=11)
  22.  
  23.  
  24.         #get image in user_profile_pics
  25.         with open(img_dir + img_path, "rb") as image_file:
  26.             encoded_string = base64.b64encode(image_file.read())
  27.         return encoded_string
  28.  
  29.         c.close()
  30.         conn.close()
  31.  
  32.     except Exception as e:
  33.         return str(e)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top