Error on running Django based MongoDB web admin - python

I am trying to install Fan-of-Mongo a web admin for MongoDB which is based on Django I think.
I believe I have followed the instructions from here:
https://github.com/Fiedzia/Fang-of-Mongo
When I run this command:
python ./manage.py runserver
I get this error:
File "/usr/lib/python2.4/site-packages/Django-1.3.1-py2.4.egg/django/conf/__init__.py", line 125, in __init__ raise ValueError("Incorrect timezone setting: %s" % self.TIME_ZONE)
ValueError: Incorrect timezone setting: Warsaw/Poland
Can anyone here give me an idea on how to fix this?

The correct timezone for Warsaw is Europe/Warsaw. Just fix your settings.py.

The error is because of the reason that it cannot find the timezone info inside "/usr/share/zoneinfo/" directory. The following is the solution:
try whether the timezone present in the /usr/share/zoneinfo/ directory.
If the time zone is not present then go to fangofmongo extracted directory and open form/settings.py change the TIME_ZONE = 'America/North_Dakota' (America/North_Dakota) these should be in your "zone info" directory

Related

Unable to run PyTest-bdd step definition file as it throws index out of range error

Feature file is as below
Feature: Nopcommerce Login
Scenario: login to nopcommerce website
Given nopcommerce page is displayed
When user enters username as admin#yourstore.com
When user enters password as admin
Then user is able to login to nocpmmerce website
step definition python file is as below
from pytest_bdd import scenarios, given, when, then
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pytest
scenarios('../features/NopcommerceLogin.feature')
#pytest.fixture()
def browser():
driver = webdriver.Safari()
yield driver
driver.quit()
#given("nopcommerce page is displayed")
def webpage(browser):
browser.get("http://admin-demo.nopcommerce.com")
#when("user enters username as admin#yourstore.com")
def enter_uname(browser):
browser.find_element_by_id("Email").send_keys("admin#yourstore.com")
#when("user enters password as admin")
def enter_pwd(browser):
browser.find_element_by_id("Password").send_keys("admin")
browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div/div[2]/div[1]/div/form/div[3]/input").click()
#then("user is able to login to nocpmmerce website")
def loginsuccess(browser):
assert browser.current_url == "https://admin-demo.nopcommerce.com/admin/"
when the step_def file is run, the following error message is displayed
Traceback (most recent call last):
File "~/tests/step_defs/test_NopcommerceLogin.py", line 6, in
scenarios('../features/NopcommerceLogin.feature')
File "~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py", line 343, in scenarios
features_base_dir = get_features_base_dir(module)
File "~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py", line 295, in get_features_base_dir
return get_from_ini('bdd_features_base_dir', default_base_dir)
File "~/venv/lib/python3.8/site-packages/pytest_bdd/scenario.py", line 303, in get_from_ini
config = CONFIG_STACK[-1]
IndexError: list index out of range
It's not entirely the solution, and I have the same issue in PycharmIDE, but I suggest using terminal and start tests like:
pytest <test_fily.py>
for IDEA solution, still working on it
Change your configurations to use pytest configuration: screenshot
or try running using terminal : pipenv run python -m pytest
I guess the problem is that the pytest is not identifying any executable pytest method's in your step definition file. Please try changing the "scenarios" to "scenario" and add a pytest identifiable method below the same
#scenario('../features/NopcommerceLogin.feature')
def test_login():
pass
This approach always works for me and is based on Pytest-BDD doc.
Make sure that pytest configured in pycham
Enable Pytest for your project
Open the Settings/Preferences | Tools | Python Integrated Tools settings dialog as described in Choosing Your Testing Framework.
In the Default test runner field select pytest.
Click OK to save the settings
#Vova
I found that in the run configuration, the Working directory was incorrectly set to the directory where the steps python file was, instead of the project root directory.
Fixing that made the test run successfully in PyCharm.
I had this issue - it was simply alignment in the feature file, I had a space on the Scenario definition after 'Scenario' and before the colon. When I removed - the error no longer occured.

Flask SqlAlchemy/Alembic migration sends invalid charset to PyMysql

I've spent a 3+ hours on this for 18 of the last 21 days. Please, someone, tell me what I'm misunderstanding!
TL;DR: My code is repeatedly sending the db charset as a string to PyMysql, while it expects an object with an attribute called "encoding"
Background
This is Python code running on a docker container. A second container houses the database. The database address is stored in a .env variable called ENGINE_URL:
ENGINE_URL=mysql+pymysql://root:#database/starfinder_development?charset=utf8
I'm firing off Alembic and Flask-Alembic commands using click commands in the CLI. All of the methods below are used in CLI commands.
Models / Database Setup (works)
from flask import Flask
flask_app = Flask(__name__)
db_engine = SQLAlchemy(flask_app)
from my_application import models
def create_database():
db_engine.create_all()
At this point I can open up the database container and use the MySql CLI to see that all of my models have now been converted into tables with columns and relationships.
Attempt 1: Alembic
Create Revision Files with Alembic (works)
from alembic.config import Config
def main(): # fires prior to any CLI command
filepath = os.path.join(os.path.dirname(__file__),
"alembic.ini")
alembic_config = Config(file_=filepath)
alembic_config.set_main_option("sqlalchemy.url",
ENGINE_URL)
alembic_config.set_main_option("script_location",
SCRIPT_LOCATION)
migrate_cli(obj={"alembic_config": alembic_config})
def revision(ctx, message):
alembic_config = ctx.obj["alembic_config"]
alembic_command.revision(alembic_config, message)
At this point I have a migration file the was created exactly as expected. Then I need to upgrade the database using that migration...
Running Migrations with Alembic (fails)
def upgrade(ctx, migration_revision):
alembic_config = ctx.obj["alembic_config"]
migration_revision = migration_revision.lower()
_dispatch_alembic_cmd(alembic_config, "upgrade",
revision=migration_revision)
firing this off with cli_command upgrade head causes a failure, which I've included here at the bottom because it has an identical stack trace to my second attempt.
Attempt 2: Flask-Alembic
This attempt finds me completely rewriting my main and revision commands, but it doesn't get as far as using upgrade.
Create Revision Files with Flask-Alembic (fails)
def main(): # fires prior to any CLI command
alembic_config = Alembic()
alembic_config.init_app(flask_app)
migrate_cli(obj={"alembic_config": alembic_config})
def revision(ctx, message):
with flask_app.app_context():
alembic_config = ctx.obj["alembic_config"]
print(alembic_config.revision(message))
This results in an error that is identical to the error from my previous attempt.
The stack trace in both cases:
(Identical failure using alembic upgrade & flask-alembic revision)
File "/Users/MyUser/.pyenv/versions/3.6.2/envs/sf/lib/python3.6/site-packages/pymysql/connections.py", line 678, in __init__
self.encoding = charset_by_name(self.charset).encoding
AttributeError: 'NoneType' object has no attribute 'encoding'
In response, I went into the above file & added a print on L677, immediately prior to the error:
print(self.charset)
utf8
Note: If I modify my ENGINE_URL to use a different ?charset=xxx, that change is reflected here.
So now I'm stumped
PyMysql expects self.charset to have an attribute encoding, but self.charset is simply a string. How can I change this to behave as expected?
Help?
A valid answer would be an alternative process, though the "most correct" answer would be to help me resolve the charset/encoding problem.
My primary goal here is simply to get migrations working on my flask app.

Django 1.4 syncdb + psycopg fails with Timezone Error

After installing Postgres.app on MacOS, and initialising a python virtualenv with Django, dj-database-url, and psycopg2 I repeatedly got:
/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 194, in _cursor
self.ops.set_time_zone_sql(), [tz])
psycopg2.DataError: invalid value for parameter "TimeZone": "UTC"
When executing "python manage.py syncdb" for my Django app.
Any ideas on what the cause is?
When I examined line 194 of the base.py file I noticed the following code:
tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')
By changing the USE_TZ parameter in my settings.py file to 'False' I then got the following error:
psycopg2.DataError: invalid value for parameter "TimeZone": "Australia/Perth"
"Australia/Perth" was the timezone setting in my settings.py file so at least it was accessing my timezone now.
Looking again at psycopg2 base.py file I noticed the following code:
if tz:
try:
get_parameter_status = self.connection.get_parameter_status
except AttributeError:
# psycopg2 < 2.0.12 doesn't have get_parameter_status
conn_tz = None
else:
conn_tz = get_parameter_status('TimeZone')
if conn_tz != tz:
Putting a debug 'print conn_tz' into base.py showed that conn_tz (presumably the timezone setting of the postgres db) was 'Australia/West'.
Changing my settings.py TIME_ZONE to 'Australia/West' allowed syncdb to run normally.

remote: missing/incomplete bugzilla conf (no bugzilla_url) error with gitzilla

I have gitzilla config file setup at /ect/gitzillarc on remote central repository server with permissions all read and write.
Content of the file code config is as follows
[/home/gituser/repositories/git-main/git-main.git/.git]
bugzilla_url: https://repo.example.com/bugzilla/
bugzilla_user: sboppana#example.com
bugzilla_password: s123
user_config: deny
allowed_bug_states: NEW, ASSIGNED, REOPENED
logfile: /var/log/gitzilla.log
loglevel: info`
python at 2.6.5
pybugz at 0.9.3 (tried with 0.8.0 also)
Gitzilla at gera-gitzilla-gitzilla-2.0-19-geceeaca.tar.gz
I get the error "remote: missing/incomplete bugzilla conf (no bugzilla_url)" with git push
Of course bugzilla_url value has the real name in my config file not the example name.
Tried many but couldn't get it to work. Thanks for all the help.
Adding xmlrpc.cgi along with the bugzilla URL should solve this issue. This is the workaround for the problem in Pybugz.
For instance, if your bugzilla URL is https://repo.example.com/bugzilla/ try using https://repo.example.com/bugzilla/xmlrpc.cgi This should work.

Two different python paths in showing up Django

I see two different python paths in django.
This one shows up with the development server(i.e. python manage.py runserver etc.):
['/var/www/html/django/congressticketing',
'/usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/pisa-3.0.32-py2.4.egg',
'/usr/lib/python2.4/site-packages/Whoosh-0.3.9-py2.4.egg',
'/usr/lib/python2.4/site-packages/html5lib-0.11-py2.4.egg',
'/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg','/usr/lib/python2.4/site-packages/anyjson-0.2.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/SQLAlchemy-0.6.0-py2.4.egg',
'/usr/lib/python2.4/site-packages/mailer-0.5-py2.4.egg',
'/usr/lib/python2.4/site-packages/python_dateutil-1.5-py2.4.egg',
'/usr/lib/python2.4/site-packages/simplejson-2.1.1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/dottedish-0.6-py2.4.egg',
'/usr/lib/python2.4/site-packages/simplegeneric-0.6-py2.4.egg',
'/usr/lib/python2.4/site-packages/supervisor-3.0a8-py2.4.egg',
'/usr/lib/python2.4/site-packages/elementtree-1.2.7_20070827_preview-py2.4.egg', '/usr/lib/python2.4/site-packages/meld3-0.6.6-py2.4.egg',
'/usr/lib/python2.4/site-packages/billiard-0.3.1-py2.4.egg',
'/usr/lib/python2.4/site-packages/pycrypto-2.2-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/Trac-0.12-py2.4.egg',
'/usr/lib/python2.4/site-packages/Genshi-0.6-py2.4.egg',
'/usr/lib/python2.4/site-packages/django_thumbnail_works-0.2.0-py2.4.egg', '/usr/lib/python2.4/site-packages/cropresize-0.1.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/uuid-1.30-py2.4.egg',
'/usr/lib/python2.4/site-packages/pyparsing-1.5.5-py2.4.egg',
'/usr/lib/python2.4/site-packages/carrot-0.10.7-py2.4.egg',
'/usr/lib/python2.4/site-packages/django_compress-1.0.1-py2.4.egg', '/usr/lib/python2.4/site-packages/BeautifulSoup-3.2.0-py2.4.egg',
'/usr/lib/python2.4/site-packages/lxml-2.3beta1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/django_celery-2.1.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/sorl_thumbnail-10.12-py2.4.egg', '/usr/lib/python2.4/site-packages',
'/usr/lib/python24.zip',
'/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2',
'/usr/lib/python2.4/lib-tk',
'/usr/lib/python2.4/lib-dynload',
'/usr/lib/python2.4/site-packages/Numeric',
'/usr/lib/python2.4/site-packages/PIL',
'/usr/lib/python2.4/site-packages/gtk-2.0']
This one - much shorter - shows up in production(using mod_python):
['/var/www/html/django/congressticketing',
'/usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/pisa-3.0.32-py2.4.egg',
'/usr/lib/python2.4/site-packages/Whoosh-0.3.9-py2.4.egg',
'/usr/lib/python2.4/site-packages/html5lib-0.11-py2.4.egg',
'/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/anyjson-0.2.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/SQLAlchemy-0.6.0-py2.4.egg',
'/usr/lib/python2.4/site-packages/python_dateutil-1.5-py2.4.egg',
'/usr/lib/python2.4/site-packages/simplejson-2.1.1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/dottedish-0.6-py2.4.egg',
'/usr/lib/python2.4/site-packages/supervisor-3.0a8-py2.4.egg',
'/usr/lib/python2.4/site-packages/billiard-0.3.1-py2.4.egg',
'/usr/lib/python2.4/site-packages/Trac-0.12-py2.4.egg',
'/usr/lib/python2.4/site-packages/django_thumbnail_works-0.2.0-py2.4.egg', '/usr/lib/python2.4/site-packages/cropresize-0.1.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/pyparsing-1.5.5-py2.4.egg',
'/usr/lib/python2.4/site-packages/carrot-0.10.7-py2.4.egg',
'/usr/lib/python2.4/site-packages/BeautifulSoup-3.2.0-py2.4.egg',
'/usr/lib/python2.4/site-packages/lxml-2.3beta1-py2.4-linux-i686.egg', '/usr/lib/python2.4/site-packages/django_celery-2.1.4-py2.4.egg',
'/usr/lib/python2.4/site-packages/sorl_thumbnail-10.12-py2.4.egg', '/usr/lib/python2.4/site-packages',
'/usr/lib/python24.zip',
'/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2',
'/usr/lib/python2.4/lib-tk',
'/usr/lib/python2.4/lib-dynload',
'/usr/lib/python2.4/site-packages/Numeric',
'/usr/lib/python2.4/site-packages/PIL',
'/usr/lib/python2.4/site-packages/gtk-2.0']
Does anyone have any idea why this is?
It could be a permissions problem. Check the file and directory permissions on the missing site-packages. It could be that those files are not accessible to the user name under which mod_python or Apache is running.

Categories

Resources