I try to add a few extra fields in web2py's auth user register form. The part auth.setting.extra_fields['auth_user'] is what I added to models/db.py
auth = Auth(db)
crud, service, plugins = Crud(db), Service(), PluginManager()
auth.settings.extra_fields['auth_user'] = [
Field('address'),
Field('city'),
Field('zip'),
Field('image','upload')
]
## create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)
All fields except the image field seem work fine.
But when I try to upload an image to 'Apply Changes',
I got IOERROR Error2 No such file or directory: "....jpg"
The web server runs locally and the image is in my computer.
Am I missing any thing?
Thanks!
I try to create a new app and add this :
auth.settings.extra_fields['auth_user'] = [
Field('address'),
Field('city'),
Field('zip'),
Field('image','upload')
]
in app/models/db.py like you did as far as I can see.
Then I create a new user with appadmin and insert a image in my image field of type upload. It worked out of the box with web2py 2.4.7
Maybe provide the version of web2py you use could help to find the issue you face.
Your problem maybe be coming from permissions or web server configuration, but without detailed informations about you setup, I can't help.
Note: You could have more help on the mailing-list here :
https://groups.google.com/forum/#!forum/web2py
The community of web2py is very freindly and helping.
Cheers
Richard
Related
I'm a beginner in Django and I'm studying Django from the book "Django 2 by Example", written by Antonio Mele. I'm trying to add social authentication to my site(book page no. 251) {project name-bookmark, app name-account}. Up to this point, I'm installed the Django package
"social-auth-app-django",
synced python-social-auth models with database using migration and added "social_django" to the INSTALLED_APPS settings of my project. Then I've added
path('social-auth/', include('social_django.urls', namespace='social')),
now it is telling me to edit my hosts file located at "C:\Windows\System32\Drivers\etc\hosts" and to add "127.0.0.1 mysite.com" line which I've added. After this running server "http://example.com:8000/account/login/" should give error, here example.com is actually mysite.com,
DisallowedHost at /account/login:
Invalid HTTP_HOST header:'mysite.com:8000'.You may need to add 'mysite.com' to ALLOWED_HOSTS.
But I don't know why it isn't showing instead of that it gives me "This site can’t be reached. mysite.com refused to connect."
But it works perfectly fine at 127.0.0.1:8000.
Please help me I'm stuck. I've searched on google as well as watched videos on youtube but still, this error can't be solved(generated) by me.
Edit the hosts file in your etc folder.
Don't add the # on the line that contains your new line adding mysite.com
The App is public and it has been granted the appropriate permissions:
Display of app permissions
My logged in user is an administrator to the App: Display of user permissions
The code is as follows:
import facebook
import warnings
# Hide deprecation warnings. The facebook module isn't that up-to-date (facebook.GraphAPIError).
warnings.filterwarnings('ignore', category=DeprecationWarning)
# Parameters of your app and the id of the profile you want to mess with.
FACEBOOK_APP_ID = 'SECRET'
FACEBOOK_APP_SECRET = 'SECRET'
FACEBOOK_PROFILE_ID = 'SECRET'
fb_api=facebook.GraphAPI()
api_token=fb_api.get_app_access_token(app_id=FACEBOOK_APP_ID, app_secret=FACEBOOK_APP_SECRET, offline=True)
graph = facebook.GraphAPI(api_token)
# Try to post something on the wall.
try:
fb_response = graph.put_object(parent_object=FACEBOOK_PROFILE_ID, connection_name='feed',
message='Hello, world')
print(fb_response)
except facebook.GraphAPIError as e:
print('Something went wrong:', e.type, e.message)
This code fails with the error message:
OAuthException (#200) Requires either publish_actions permission, or manage_pages and publish_pages as an admin with sufficient administrative permission
I am certain at this point I have followed all the things I've read in any other post. The docs they have for the sdk are here.
A bunch of stuff is just not working so here's what I did. I created a link and then I just click on it:
https://developers.facebook.com/docs/php/howto/example_facebook_login
This is super duper easy with something like laravel or lumen. You just make a controller and a route that points to it.
I upload the token to a local consul instance so I can access it across a variety of micro services.
I use puppeteer to login to facebook via my stub site and then I have a token and login cookies too.
we found facebook change the permission requirements for posting to pages from just manage_pages to require both manage_pages and publish_pages. by granting both permissions we solved our problem
in essence we had to pass the client to
https://www.facebook.com/dialog/oauth?client_id=client_id&redirect_uri=redirect_uri&scope=manage_pages,publish_pages&response_type=code%20token&enable_profile_selector=1&profile_selector_ids=pageid
I have tried the bluemix service 'APP ID' for node.js project which I downloaded from APP ID service instance only. The application runs well with Google and Facebook authentication.
But I have to apply authentication to Python Flask web application. For this,I have followed the github link . Here, I have provided 'clientid', 'secret' and 'redirect_uri' which I got from the 'Service Credentials' tab of the 'APP ID' instance in bluemix.
After running the app, I am getting login page but when I click 'Login' button then I am getting the error 'tenandid is in invalid format'.
Please suggest where I am doing wrong.
Thanks in advance !
Regards,
Rahul Modi
I solved the error my self. I just provided clientId, secret, redirectUri and serverUrl in the file serviceConfig.py file of the GitHub python project.
There is need to change this file by providing the above parameters otherwise you may land into the error on the line "clientId = serviceConfig.clientId" of 'welcome.py' because clientId is not accessible from serviceConfig class. The same case for 'secret' as well. Hence, define them separately in serviceConfig.py file.
The four parameters looks like below:
serverUrl='https://appid-oauth.ng.bluemix.net/oauth/v3/1b668c6a-XXXX-XXXX-XXXX-c4633e8e0c78'
redirectUri='http://localhost:5000/afterauth'
secret='NjNiODY5NDQtOXXXXXXXXXXXXXXXXXXXXzUxNDMzNzYxYjAy'
clientId='6284418c-XXXX-XXXX-XXXX-af8bf44588ec'
All these parameters you can collect from the 'Service Credentials' tab of the 'APP ID' instance in Bluemix.
Note: No need to change anything in 'welcome.py' file.
I'm running a python 2.7 app in google app engine. I have a very basic function that sends a post to the taskqueue, which then posts to a function that constructs and sends an email based on a few variables parsed into a mail template.
I'm not sure if the taskqueue is stuck on an old version of my app or what the problem is, but when I update the code in the file that sends the email, and upload the changes, those changes are not causing any the email text the app sends. It's like it's using a wrong older version of the file.
What could be the cause of this issue?
edit
Just of note, this is what I've tried so far.
I tried updating the app to a new version, but there was no change
I tried editing other files in the project, and they all seem to update correctly
I am using the oauth method for uploading with a .bat file to run the command, and there's no refreshing needed there because updating the app version didn't help
I tried moving the email code that I want to use out of its old class, into a new class, changed the main.py url to point to the new class, and it still uses the old email text
I tried removing the old url for triggering the email and using an entirely new url, and it still uses the old email text
I tried testing the app using the version-number.project-id.appspot.com format, and it still uses the old email text, which doesn't exist anywhere in that version
So to reiterate, I'm trying to send an email with my app, and even with the old message being totally removed, the email code being moved to a new file, and a new app version, somehow I'm still sending out the old email text.
edit 2
This is the relevant code for queuing the task:
taskqueue.add(url="/emailnotify", countdown = 1,
params = {"email":tPaypalEmail, "gold":tGoldAmount,
"name":tCustomerName, 'key':tOrderKey} )
This is the relevant code in the class that's supposed to send the email:
from cStringIO import StringIO
import webapp2
from models.order import Order
from google.appengine.api import mail
from google.appengine.ext import db, webapp
from _stringmethods import StringMethods
from _numbertogp import NumberToGp
class EmailNotify(webapp2.RequestHandler):
def post(self):
tPaypalEmail = self.request.get('email')
tCustomerName = self.request.get('name')
tGoldAmount = self.request.get('gold')
tOrderKey = self.request.get('key')
tOrder = Order()
tOrder = Order.get(tOrderKey)
tVerificationCode = tOrder.orderVerificationCode
tGoldInt = int(tGoldAmount)
tGoldAmount = NumberToGp.ConvertIntToBet(tGoldInt)
tVerificationFile = cStringIO.StringIO()
tVerificationFile.write(str(tVerificationCode))
#new message which does not appear in the app emails
tMessage = """Long string formatted message""" % (str(tCustomerName), str(tGoldAmount), str(tVerificationCode))
logging.debug(str(tMessage)) #this does not appear in the logs
message = mail.EmailMessage()
message.sender = "Smokin Mils Goldshop <Smokin.Mils.Goldshop#gmail.com>" #this email user is added as an app owner
message.to = tPaypalEmail
message.subject = "SmokinShop Order Details"
message.body = tMessage
message.attachments = [('verification-code.txt', tVerificationFile.getvalue())]
message.send()
edit 3
In response to the reddit question where I posted this problem, here is the queue.yaml
queue:
- name: default
rate: 60/s
bucket_size: 50
retry_parameters:
min_backoff_seconds: 2
max_backoff_seconds: 200
task_retry_limit: 10
Had a similar issue when deploying several lines of an email servlet (on GAE/J) from Eclipse. Finally fixed it after trying in vain the versioning, overwriting older versions, deleting version, playing around with tread-safe, changing the class name, changing the class signature (constructor) MemCache, etc. (none of this worked.)
Bottom line: delete 'deploy' and 'classes' folders in your WEB-INF directory. Clean/build your project again. Then upload to App Engine.
This 'deep clean / start over' approach seemed to do the trick. What's annoying is that this never seemed necessary before. It was only when I started playing with Email and PDF code using external libraries did this seem to cause issues. I also upgraded to App Engine 1.8 recently. Would love to know the root cause of this but I'm tired of doing Google's debugging for them at this point. Just glad I seemed to find a solution.
Interesting background discussion: http://code.google.com/p/googleappengine/issues/detail?id=7335
My question is about how to serve multiple urls.py (like urls1.py, urls2.py and so on) files in a single Django project.
I am using Win7 x64, django 1.4.1, python 2.7.3 and as a server django dev-server tool.
I have decided to use a method which i found by google from
http://effbot.org/zone/django-multihost.htm
I have created a multihost.py file and put in to the django middleware folder:
C:\python27\Lib\site-packages\django\middleware\multihost.py
With the following code:
from django.conf import settings
from django.utils.cache import patch_vary_headers
class MultiHostMiddleware:
def process_request(self, request):
try:
host = request.META["HTTP_HOST"]
if host[-3:] == ":80":
host = host[:-3] # ignore default port number, if present
request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
except KeyError:
pass # use default urlconf (settings.ROOT_URLCONF)
def process_response(self, request, response):
if getattr(request, "urlconf", None):
patch_vary_headers(response, ('Host',))
return response
Also in my project setting.py file i have added a mapping dictionary like the link above shows:
# File: settings.py
HOST_MIDDLEWARE_URLCONF_MAP = {
"mysite1.com": "urls1",
#"mysite2.com": "urls2"
}
I did not yet implemented the error handling like described by the link above.
My hosts file includes the follwoing:
127.0.0.1 mysite1.com
Project structure is the following:
effbot django project folder:
+ effbot
--- settings.py
--- view.py
--- wsgi.py
--- urls.py
--- urls1.py
+ objex
--- models.py
--- views.py
+ static
--- css
--- images
There is no templates folder, because i dont serve html items from files, they are coming from databsse (i doubt that my problem is in this).
Now the problem is: when i go for the adress
mysite1.com
in my browser with django dev-server launched i get code 301 from the server. And browser shows "cannot display page" message.
Could you please explain me how to use mentioned method? I'm new to django and haven't done any real projects yet. Just have read the docs and launched a couple of sites at home to learn how it works.
I expect that urlconfs will be called in dependance from incoming
request.META["HTTP_HOST"]
The target is to serve different urlconfs for mysite1.com and mysite2.com
in a single django project.
I think this should to work some how.
Thank you for any feedback.
EDIT:
After some research attempts i found that i plugged my multyhost.py incorrectly in settings.
Fixed now. But the same result still.
Also i found out that my django dev-server tool is not reflecting anyhow that it handles any requests from the browser (IE9) except when i do "http://127.0.0.1".
May be i have to try some production server for my task, like nginx?
Your ROOT_URLCONF should be effbot.urls without .pyas you can see in the example in the documentation.
Also, HOST_MIDDLEWARE_URLCONF_MAP should reflect the ROOT_URLCONF so add `effbot. like this:
HOST_MIDDLEWARE_URLCONF_MAP = {
"mysite1.com": "effbot.urls1",
#"mysite2.com": "effbot.urls2"
}
One more thing, please try with another browser (Chrome, Firefox), sometimes I had problems accessing dev server with IE.