Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement