routes on error functionality not working in web2py - python

i am trying to present a custom error to the end user , but these custom routes are not working and i am still being shown default ticker number, since exposing ticker numbers pose security issues, what am i missing? need help in this thanks in advance ,
Also i have these routes in routes.py in project level directory adjacent to web2py.py
routes_onerror = [
('gms/404', '/gms/static/404.html'),
('gms/500', '/gms/static/500.html'),
('gms/408', '/gms/static/404.html'),
('gms/400', '/gms/static/404.html'),
('super/*', '/super/static/404.html'),
(r'*/*', r'/gms/static/404.html'),
]

Related

How to get the parent folder name of Message with Exchangelib python

I have an Item object obtained by filtering on an account using exchangelib in python 3.7. It is an email object. I need to find the parent folder name of this item. I specifically need the name field of the folder(This is for tracking where specific emails are moved in a mailbox).
I can see a field parent_folder_id in the item object which returns what I think is a valid folder id. This is also for a production mailbox where account.root.get_folder(folder_id=idObj) times out due to Exchange settings which I cannot change. Pretty much any request which caches fails with a timeout.
account=Account(...)
mailItems=account.inbox.all().filter(subject="foo")
print([i.parent_folder_id.id for i in mailItems])
This prints a list of folder ids. I need the names of these folders. Unclear how to proceed. Any help would be appreciated
Since you're only searching account.inbox and not its subfolders, parent_folder_id will always point to account.inbox.
There's not a very good API yet for looking up folders by e.g. ID. The best solution currently is to use a folder QuerySet:
from exchangelib.folders import SingleFolderQuerySet
f = SingleFolderQuerySet(
account=account,
folder=account.root
).get(id=i.parent_folder_id.id)

DocuSign python (eg-03-python-auth-code-grant) authentication server problem

I am able to get on Docusign example page on my localhost:5000 fine but when I click on any of the 23 links it redirects me to localhost/ds/must_authenticate.
- I click on “authenticate with DocuSign” link and it takes me to account-d.docusign.com/#/password
-I enter my credentials and then it takes me appdemo.docusign.com/home
I am trying to do one of the many examples from the DocuSign GitHub repo on https://github.com/docusign/eg-03-python-auth-code-grant . The only thing I have changed is In the ds_config to add my client_id, client_secret, signer_email, signer_name, session_secret, and I had to add /oauth on line 14 in the ds_config. Changing it from authorization_server": "https://account-d.docusign.com to authorization_server": "https://account-d.docusign.com/oauth . The reason I added /oauth is because I get a client id error. The redirect URI I used in my integration key is http://localhost:5000/ds/callback. I guess I am having an issue with with the authorization_server. If I omit or keep brackets I get same results and can get past login. The url paths are : 127.0.0.1:5000 for homepage, then I click on any of the example links and get redirected to sign in page 127.0.0.1:5000/ds/must_authenticate, Then I click on the "authenticate with DocuSign" and get redirected to account.d.docusign.com/username#/password, then ""/password, then appdemo.docusign/authentication, then appdemo.docusign/redirect?to, then appdemo.docusign.com/home. I keep getting redirected to Docusign Homepage. If I take /oauth out of authorization server then I cant get past sign in page.
DocuSignIntegrationKeyandRedirectURI
OAuthSignInError DS_Config w/o brackets and w/o /oauth
DS_Config.py w/o brackets and w/o oauth
DS_CONFIG.PY
Thank you for submitting your question. On first glance, I see that your DS_Config.Py needs a couple of quick alterations. Can you try the following and let me know if you're still having issues with the OAuth flow?
1) Remove the { }'s from the config file. if you're listing your ds_client_id as {client_Id} it reads the {} as part of the ID, which will return an error indicating the key isn't properly registered with DocuSign. You'll want to remove the brackets from the first 5 variables in your config file.
2) Move the authorization_server back to the original URL (excluding '/oauth')
Let me know if that works for you, if you see another error on your side please reply with the exact error message with a screenshot if possible, then we can pick it up from there.
A current workaround I have found is editing the views.py ds_token_ok function. On line 177, the ok boolean variables are not returning true. Not sure if it is a session problem. I edited the return statement to return True instead of ok, this has let me open all the links in the python application and run all the examples.
def ds_token_ok(buffer_min=60):
# :param buffer_min: buffer time needed in minutes
#:return: true iff the user has an access token that will be good for #another buffer min
ok = "ds_access_token" in session and "ds_expiration" in session
ok = ok and (session["ds_expiration"] - timedelta(minutes=buffer_min)) > datetime.utcnow()
#comment: was return ok but I am not able to run program. Problem in line 177
return True
This is just a temporary solution to work in the sandbox.

Understanding Todoist-API

I am trying to use the Todoist-API for Python. I found the official docs on the internet and downloaded the GitHub-Repo. Unfortunately I don't get out how to add a new task.
I do the normal login:
api = todoist.TodoistAPI(XYZ)
api.sync
Then I try to add a new task:
item = api.items.add('Task1')
It tells me I have to give two arguments: name and project_id:
item = api.items.add('Task1', 128501470)
Does anyone know where I could get all my projects IDs? I just want to use the Inbox-Project (default).
I'm not very familiar with this specific API, but considering you're using this api: https://github.com/doist/todoist-python, you can probably do something like:
response = api.sync()
projects = response['projects']
for project in projects:
print(project['name'] + '-' + project['id'])
Basically printing all the names and id's
Just open Todoist in a web browser and look at the address bar, it's right after "project", I beleive you need to truncate the first three or 4 characters though, click through a few projects and you'll see the project id's change.
To add them to the inbox the easiest way is to do the following:
from todoist.api import TodoistAPI
apiToken = 'your token"
todoist: TodoistAPI = TodoistAPI(api_token)
response = todoist.add_item("Item1")
todoist.sync()
todoist.commit()
You will have to refresh either the web page or your app to immediately see the new item

Trying to change a username in Python Google Admin SDK

I'm trying to change a username using the Admin SDK. I'm trying the following code to update this, using a dict object to store the new info, and using patch to update:
userinfo['primaryEmail'] = D['new_user'] + '#' + D['domain']
appsservice.users().patch(userKey = userEmail, body=userinfo)
It doesn't seem to be working, when I look at the admin console. The original username remains unchanged. I'm just wondering if I'm using the correct method. Should I be updating a different variable than primaryEmail or without using the domain affiliation? Seems like I'm just missing something rather obvious.
Thanks,
Tom
Add:
.execute()
To the end of the 2nd line to actually execute the api operation.

Django i18n: Common causes for translations not appearing

I am making a multilingual Django website. I created a messages file, populated and compiled it. I checked the site (the admin in this case,) in my wanted language (Hebrew) and most phrases appear in Hebrew like they should, but some don't. I checked the source and these still appear as _('Whatever') like they should, also they are translated on the messages file, and yes, I remembered to do compilemessages.
What are some common causes for translations not to appear like that?
Maybe the translated strings are marked as fuzzy?
Just got hit by one. I had the locale/ directory in the root of my project, but by default Django looks for translations in the INSTALLED_APPS directories, and in the default translations. So it didn't find the translations I added. But some of my strings were in the default translations that come with Django (eg "Search") so a few strings were translated, which confused me.
To add the directory where my translations were to the list of places that Django will look for translations, I had to set the LOCALE_PATHS setting. So in my case, where the locale/ directory and settings.py were both in the root of the django project I could put the following in settings.py:
from os import path
LOCALE_PATHS = (
path.join(path.abspath(path.dirname(__file__)), 'locale'),
)
I'm trying to provide a complete check list:
In settings.py, are USE_I18N, USE_L10N, LANGUAGE_CODE, and LOCALE_PATHS set properly?
See this list for all allowed values of language identifiers. Note that Simplified Chinese is specified by zh-hans, not zh-cn.
In settings.py, is django.middleware.locale.LocaleMiddleware included in MIDDLEWARE in correct order?
Have you (re)run django-admin makemessages -l <locale-name> with the correct local name, from the correct place?
You can see an incomplete list of allowed locale name by running ls your/path/to/python/site-packages/django/conf/locale/ on your machine, or by taking a look at the source code
Note that you have to use _ rather than - here. For example, to specify simplified Chinese, execute django-admin makemessages -l zh_Hans, not zh_CN or zh_hans or zh-Hans or anything else.
Have you removed all fuzzy tags in your PO file(s)?
Have you (re)compiled the OP file(s) with django-admin compilemessages?
Have you restarted the web server?
Additional notes:
If some of your translation is overridden by Django's default translation, use contextual markers to bypass it. For example,
models.py
first_name = models.CharField(
pgettext_lazy('override default', 'first name'),
max_length=30
)
last_name = models.CharField(
pgettext_lazy('override default', 'last name'),
max_length=150
)
django.po
#: models.py:51
msgctxt "override default"
msgid "first name"
msgstr "姓"
#: models.py:55
msgctxt "override default"
msgid "last name"
msgstr "名"
and you'll see 姓, 名 instead of the default 姓氏, 名字.
I was having this problem with my project right now. I had the variable LANGUAGES on settings.py set this way:
LANGUAGES = (
('en', _('English')),
('pt-br', _('Brazilian Portuguese')),
)
And a folder structure with a locale folder, and a subfolder pt-br inside. Turns out that my translations weren't loading. The LANGUAGES variable follows the pt-br pattern, and the folders must be on pt_BR pattern. At least that's the only way it's working here!
Hi just attach some fixes I had to do in the past:
Restart the webserver!
In the setting file
- USE_I18N = True is needed
django.middleware.locale.LocaleMiddleware among middleware modules (but this is not your case for sure as long as Django will not care about your local at all)
django.core.context_processors.i18n among TEMPLATE_CONTEXT_PROCESSORS
for sure I had other issues related to translations but I don't remember them all... hope this can help!
A possible cause is Lazy Translation.
In example, in views.py you should use ugettext:
from django.utils.translation import ugettext as _
But in models.py, you should use ugettext_lazy:
from django.utils.translation import ugettext_lazy as _
Another cause can be a wrong directory structure.
Read well the manage command's error message about which directory to create before running the makemassages command for the app translation. (It must be locale for an app, not conf/locale.) Note that the management commands work fine even with the wrong directory structure.
I noticed that when I had % in my text, the translated text was not being used. There may be other characters that can cause this problem. I fixed the problem by escaping the % as %%.
My answer here, all my translations were working except for 2 DateFields that I was using in a ModelForm.
Turns out that I had a widget in my forms.py that was not working well with the translations.
I just removed it for now so I can enjoy Xmas =D

Categories