How to resolve TemplateSyntaxError: Could not parse the remainder error? - python

I'm getting a "TemplateSyntaxError: Could not parse the remainder:" here: https://docs.djangoproject.com/en/1.7/intro/tutorial05/
>>> response = client.get(reverse('polls:index'))
gets me this:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django/test/client.py", line 470, in get
**extra)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 286, in get
return self.generic('GET', path, secure=secure, **r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 358, in generic
return self.request(**r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 440, in request
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 137, in get_response
response = response.render()
File "/Library/Python/2.7/site-packages/django/template/response.py", line 103, in render
self.content = self.rendered_content
File "/Library/Python/2.7/site-packages/django/template/response.py", line 78, in rendered_content
template = self.resolve_template(self.template_name)
File "/Library/Python/2.7/site-packages/django/template/response.py", line 54, in resolve_template
return loader.select_template(template)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 188, in select_template
return get_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 144, in get_template
template, origin = find_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 132, in find_template
source, display_name = loader(name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 44, in __call__
return self.load_template(template_name, template_dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 50, in load_template
template = get_template_from_string(source, origin, template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 156, in get_template_from_string
return Template(source, origin, name)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 132, in __init__
self.nodelist = compile_string(template_string, origin)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 162, in compile_string
return parser.parse()
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 975, in do_if
nodelist = parser.parse(('elif', 'else', 'endif'))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 833, in do_for
nodelist_loop = parser.parse(('empty', 'endfor',))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 1345, in url
viewname = parser.compile_filter(bits[1])
File "/Library/Python/2.7/site-packages/django/template/base.py", line 372, in compile_filter
return FilterExpression(token, self)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 588, in __init__
"from '%s'" % (token[upto:], token))
TemplateSyntaxError: Could not parse the remainder: '\u2018polls:detail\u2019' from '\u2018polls:detail\u2019'
How to resolve this ?

You are using left quote and right quote characters when quoting the view name; where you should be using single or double quotes.
Use either 'polls:details' or "polls:details"

Related

mkdocstrings: ERROR - Error reading page 'codereference.md': <class '_ast.ExtSlice'>

I obtain the following error when typing mkdocs serve in terminal:
ERROR - Error reading page 'codereference.md': <class '_ast.ExtSlice'>
(with a very long traceback, see below)
My mkdocs.yaml file is:
site_name: Code Documentation
site_url: https://example.com/
nav:
- Home: index.md
- About: about.md
- Code: codereference.md
theme: readthedocs
plugins:
- mkdocstrings:
handlers:
python:
paths: [.]
The codereference.md file consists of the following:
# Reference
::: path.to.class.from.where.mkdocsyaml.is
Anybody have any possible answers?
The full traceback is:
Traceback (most recent call last):
File "/usr/local/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/__main__.py", line 181, in serve_command
serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/serve.py", line 63, in serve
config = builder()
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/serve.py", line 58, in builder
build(config, live_server=live_server, dirty=dirty)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/build.py", line 292, in build
_populate_page(file.page, config, files, dirty)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/commands/build.py", line 174, in _populate_page
page.render(config, files)
File "/usr/local/lib/python3.8/dist-packages/mkdocs/structure/pages.py", line 175, in render
self.content = md.convert(self.markdown)
File "/usr/local/lib/python3.8/dist-packages/markdown/core.py", line 264, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 90, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 105, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/usr/local/lib/python3.8/dist-packages/markdown/blockparser.py", line 123, in parseBlocks
if processor.run(parent, blocks) is not False:
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings/extension.py", line 121, in run
html, handler, data = self._process_block(identifier, block, heading_level)
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings/extension.py", line 195, in _process_block
data: CollectorItem = handler.collect(identifier, options)
File "/usr/local/lib/python3.8/dist-packages/mkdocstrings_handlers/python/handler.py", line 191, in collect
loader.load_module(module_name)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 148, in load_module
top_module = self._load_module(package.name, package.path, submodules=submodules)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 352, in _load_module
return self._load_module_path(module_name, module_path, submodules, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 380, in _load_module_path
self._load_submodules(module)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 385, in _load_submodules
self._load_submodule(module, subparts, subpath)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 396, in _load_submodule
member_parent[subparts[-1]] = self._load_module(
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 352, in _load_module
return self._load_module_path(module_name, module_path, submodules, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 374, in _load_module_path
module = self._visit_module(code, module_name, module_path, parent)
File "/usr/local/lib/python3.8/dist-packages/griffe/loader.py", line 413, in _visit_module
module = visit(
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 92, in visit
return Visitor(
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 172, in get_module
self.visit(top_node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 214, in visit_module
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 255, in visit_classdef
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 451, in visit_functiondef
self.handle_function(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 442, in handle_function
self.generic_visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 196, in generic_visit
self.visit(child)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 183, in visit
super().visit(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/base.py", line 19, in visit
getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[attr-defined]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 589, in visit_assign
self.handle_attribute(node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/visitor.py", line 548, in handle_attribute
value = get_value(node.value) # type: ignore[arg-type]
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1181, in get_value
return _node_value_map[type(node)](node)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1047, in _get_subscript_value
subscript = _get_value(node.slice)
File "/usr/local/lib/python3.8/dist-packages/griffe/agents/nodes.py", line 1167, in _get_value
return _node_value_map[type(node)](node)
KeyError: <class '_ast.ExtSlice'>
It's fixed in version 0.21.0 of Griffe: https://mkdocstrings.github.io/griffe/changelog/#bug-fixes
It would previously crash when unparsing values using extended slices such as o[x:y,z].

sqlalchemy.exc.ResourceClosedError: This transaction is closed

Facing the following error in a Pyramid Application while using SQLAlchemy and Zope Transaction Manager.
This is how I am creating a scoped session:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import MetaData
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
)
from zope.sqlalchemy import ZopeTransactionExtension
metadata = MetaData(naming_convention=NAMING_CONVENTION)
Base = declarative_base(metadata=metadata)
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension(keep_session=True)))
I am syncing my session creation and removal with my requests in the following way:
#view_config(route_name='social_get_individual_assets', renderer='json', effective_principals=2, permission='edit')
def social_get_individual_assets(requestJson):
session = DBSession()
try:
body = requestJson.request.json_body
search_term = body['text']
horizontal = body['horizontal']
vertical = body['vertical']
log.info("social get individual assets request: %s", str(search_term).encode(encoding='utf_8'))
json_data = get_individual_assets(session, search_term, horizontal, vertical)
log.info("social get assets response: %s", str(search_term).encode(encoding='utf_8'))
transaction.commit()
DBSession.remove()
return json_data
except Exception as e:
session.rollback()
log.exception(e)
raise e
For some reason, I keep running into this error all the time:
2017-12-06 13:32:07,965 ERROR [invideoapp.views.default:465] An operation previously failed, with traceback:
File "/usr/lib64/python3.5/threading.py", line 882, in _bootstrap
self._bootstrap_inner()
File "/usr/lib64/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 78, in handler_thread
task.service()
File "/usr/local/lib/python3.5/site-packages/waitress/channel.py", line 338, in service
task.service()
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 169, in service
self.execute()
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 399, in execute
app_iter = self.channel.server.application(env, start_response)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 270, in __call__
response = self.execution_policy(environ, self)
File "/usr/local/lib/python3.5/site-packages/pyramid_retry/__init__.py", line 114, in retry_policy
response = router.invoke_request(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 249, in invoke_request
response = handle_request(request)
File "/usr/local/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 136, in tm_tween
response = handler(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/tweens.py", line 39, in excview_tween
response = handler(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 156, in handle_request
view_name
File "/usr/local/lib/python3.5/site-packages/pyramid/view.py", line 642, in _call_view
response = view_callable(context, request)
File "/usr/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 439, in rendered_view
result = view(context, request)
File "/usr/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 148, in _requestonly_view
response = view(request)
File "/home/ttv/invideoapp/invideoapp/views/default.py", line 148, in upload_image
transaction.commit()
File "/usr/local/lib/python3.5/site-packages/transaction/_manager.py", line 131, in commit
return self.get().commit()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 308, in commit
t, v, tb = self._saveAndGetCommitishError()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 301, in commit
self._commitResources()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 446, in _commitResources
reraise(t, v, tb)
File "/usr/local/lib/python3.5/site-packages/transaction/_compat.py", line 54, in reraise
raise value
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 423, in _commitResources
rm.tpc_vote(self)
File "/usr/local/lib/python3.5/site-packages/zope/sqlalchemy/datamanager.py", line 109, in tpc_vote
self.tx.commit()
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 459, in commit
self._assert_active(prepared_ok=True)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 285, in _assert_active
raise sa_exc.ResourceClosedError(closed_msg)
sqlalchemy.exc.ResourceClosedError: This transaction is closed
Traceback (most recent call last):
File "/home/ttv/invideoapp/invideoapp/views/default.py", line 451, in update_master_json
user = getUser(session,user_id)
File "/home/ttv/invideoapp/invideoapp/invideomodules/auth_processing.py", line 12, in getUser
raise e
File "/home/ttv/invideoapp/invideoapp/invideomodules/auth_processing.py", line 8, in getUser
query = session.query(User).filter(User.user_id == userid).first()
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2755, in first
ret = list(self[0:1])
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2547, in __getitem__
return list(res)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2855, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2876, in _execute_and_instances
close_with_result=True)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2885, in _get_bind_args
**kw
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/query.py", line 2867, in _connection_from_session
conn = self.session.connection(**kw)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 966, in connection
execution_options=execution_options)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 971, in _connection_for_bind
engine, execution_options)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 417, in _connection_for_bind
self.session.dispatch.after_begin(self.session, self, conn)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/event/attr.py", line 256, in __call__
fn(*args, **kw)
File "/usr/local/lib/python3.5/site-packages/zope/sqlalchemy/datamanager.py", line 237, in after_begin
join_transaction(session, self.initial_state, self.transaction_manager, self.keep_session)
File "/usr/local/lib/python3.5/site-packages/zope/sqlalchemy/datamanager.py", line 211, in join_transaction
DataManager(session, initial_state, transaction_manager, keep_session=keep_session)
File "/usr/local/lib/python3.5/site-packages/zope/sqlalchemy/datamanager.py", line 73, in __init__
transaction_manager.get().join(self)
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 179, in join
self._prior_operation_failed() # doesn't return
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 173, in _prior_operation_failed
self._failure_traceback.getvalue())
transaction.interfaces.TransactionFailedError: An operation previously failed, with traceback:
File "/usr/lib64/python3.5/threading.py", line 882, in _bootstrap
self._bootstrap_inner()
File "/usr/lib64/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 78, in handler_thread
task.service()
File "/usr/local/lib/python3.5/site-packages/waitress/channel.py", line 338, in service
task.service()
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 169, in service
self.execute()
File "/usr/local/lib/python3.5/site-packages/waitress/task.py", line 399, in execute
app_iter = self.channel.server.application(env, start_response)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 270, in __call__
response = self.execution_policy(environ, self)
File "/usr/local/lib/python3.5/site-packages/pyramid_retry/__init__.py", line 114, in retry_policy
response = router.invoke_request(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 249, in invoke_request
response = handle_request(request)
File "/usr/local/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 136, in tm_tween
response = handler(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/tweens.py", line 39, in excview_tween
response = handler(request)
File "/usr/local/lib/python3.5/site-packages/pyramid/router.py", line 156, in handle_request
view_name
File "/usr/local/lib/python3.5/site-packages/pyramid/view.py", line 642, in _call_view
response = view_callable(context, request)
File "/usr/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 439, in rendered_view
result = view(context, request)
File "/usr/local/lib/python3.5/site-packages/pyramid/viewderivers.py", line 148, in _requestonly_view
response = view(request)
File "/home/ttv/invideoapp/invideoapp/views/default.py", line 148, in upload_image
transaction.commit()
File "/usr/local/lib/python3.5/site-packages/transaction/_manager.py", line 131, in commit
return self.get().commit()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 308, in commit
t, v, tb = self._saveAndGetCommitishError()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 301, in commit
self._commitResources()
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 446, in _commitResources
reraise(t, v, tb)
File "/usr/local/lib/python3.5/site-packages/transaction/_compat.py", line 54, in reraise
raise value
File "/usr/local/lib/python3.5/site-packages/transaction/_transaction.py", line 423, in _commitResources
rm.tpc_vote(self)
File "/usr/local/lib/python3.5/site-packages/zope/sqlalchemy/datamanager.py", line 109, in tpc_vote
self.tx.commit()
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 459, in commit
self._assert_active(prepared_ok=True)
File "/usr/local/lib64/python3.5/site-packages/sqlalchemy/orm/session.py", line 285, in _assert_active
raise sa_exc.ResourceClosedError(closed_msg)
sqlalchemy.exc.ResourceClosedError: This transaction is closed
Once I get this error, none of my Database connection stuff works. Only way out is to restart the entire application to make things work. Any idea why this is happening?
I had a similar problem, and I found using DBSession.begin_nested() solved the issue. So something like:
#view_config(route_name='social_get_individual_assets', renderer='json', effective_principals=2, permission='edit')
def social_get_individual_assets(requestJson):
try:
DBSession.begin_nested()
body = requestJson.request.json_body
search_term = body['text']
horizontal = body['horizontal']
vertical = body['vertical']
log.info("social get individual assets request: %s", str(search_term).encode(encoding='utf_8'))
json_data = get_individual_assets(session, search_term, horizontal, vertical)
log.info("social get assets response: %s", str(search_term).encode(encoding='utf_8'))
return json_data
except Exception as e:
DBSession.rollback()
log.exception(e)
raise e

Unknown PG numeric type 25

I am working on a project with Python-Flask, SQL Alchemy, & Postgres qith psycopg2 package.
The project's save the data in database successfully, but throws error "Unknown PG numeric type 25" while refreshing object.
project.second_payment_percent = int(request.form.get("second_payment_percent", 0)) if request.form.get("second_payment_percent", 0) else 0
project.second_payment_before = int(request.form.get("second_payment_before", 120))
project.currency_id = int(request.form.get("currency_code"))
project.security_deposit = int(request.form.get("security_deposit", 0))
project.apa = int(request.form.get("apa", 0))
project.vat_schema_id = request.form.get("vat_schema") if request.form.get("vat_schema", 0) else None
if project.apa > 0:
project.security_deposit = int(project.project_price) * int(project.apa) / 100
db.session.add(project)
db.session.commit()
db.session.refresh(project)
db.session.flush()
The error I get is
File "<project directory>utils/app_views.py", line 56, in decorated
return f(*args, **kwargs)
File "<project directory>views/admin/project.py", line 347, in admin_products_save_accommodation
db.session.refresh(project)
File "<project directory>models/project.py", line 297, in serialize
reviews, avg_rating = self.reviews
File "<project directory>models/project.py", line 269, in reviews
robj = db.session.query(ProjectReviews).filter_by(product_id=self.id).order_by('time_created').all()
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 237, in __get__
return self.impl.get(instance_state(instance), dict_)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 578, in get
value = state._load_expired(state, passive)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 474, in _load_expired
self.manager.deferred_scalar_loader(self, toload)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 664, in load_scalar_attributes
only_load_props=attribute_names)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 219, in load_on_ident
return q.one()
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2693, in one
ret = list(self)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2736, in __iter__
return self._execute_and_instances(context)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2751, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
return meth(self, multiparams, params)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
compiled_sql, distilled_params
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1161, in _execute_context
result = context.get_result_proxy()
File "<venv path>lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 474, in get_result_proxy
return _result.ResultProxy(self)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/result.py", line 495, in __init__
self._init_metadata()
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/result.py", line 524, in _init_metadata
self._metadata = ResultMetaData(self, metadata)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/result.py", line 221, in __init__
in enumerate(result_columns)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 764, in get_result_processor
return type_._cached_result_processor(self.dialect, coltype)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/sql/type_api.py", line 392, in _cached_result_processor
d[coltype] = rp = d['impl'].result_processor(dialect, coltype)
File "<venv path>lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 361, in result_processor
"Unknown PG numeric type: %d" % coltype)
InvalidRequestError: Unknown PG numeric type: 25
I have tried many things, but failed.
I guess one of the fields in your table is a text and you are trying to retrieve it as a number.
postgres=# select * from pg_type where oid = 25;
-[ RECORD 1 ]--+---------
typname | text

Can't use API with username and password in Scrapy

This Curl works.
https://<user>:<pass>#xecdapi.xe.com/v1/convert_from.json/?from=1000000&to=SGD&amount=AED,AUD,BDT&inverse=True
But this Scrapy request doesn't work.
yield scrapy.Request("https://<user>:<pass>#xecdapi.xe.com/v1/convert_from.json/?from=1000000&to=SGD&amount=AED,AUD,BDT&inverse=True")
It returns this error:
Traceback (most recent call last):
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\defer.py", line 1297, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\python\failure.py", line 389, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\middleware.py", line 43, in process_request
defer.returnValue((yield download_func(request=request,spider=spider)))
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\utils\defer.py", line 45, in mustbe_deferred
result = f(*args, **kw)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\__init__.py", line 65, in download_request
return handler.download_request(request, spider)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 61, in download_request
return agent.download_request(request)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 286, in download_request
method, to_bytes(url, encoding='ascii'), headers, bodyproducer)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1596, in request
endpoint = self._getEndpoint(parsedURI)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1580, in _getEndpoint
return self._endpointFactory.endpointForURI(uri)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\web\client.py", line 1456, in endpointForURI
uri.port)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\scrapy\core\downloader\contextfactory.py", line 59, in creatorForNetloc
return ScrapyClientTLSOptions(hostname.decode("ascii"), self.getContext())
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\_sslverify.py", line 1201, in __init__
self._hostnameBytes = _idnaBytes(hostname)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\twisted\internet\_sslverify.py", line 87, in _idnaBytes
return idna.encode(text)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 355, in encode
result.append(alabel(label))
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 276, in alabel
check_label(label)
File "d:\kerja\hit\python~1\<project_name>\<project_name>\lib\site-packages\idna\core.py", line 253, in check_label
raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
InvalidCodepoint: Codepoint U+003A at position 28 of u'xxxxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxx#xecdapi' not allowed
Scrapy does not support HTTP Authentication via URL. We have to use HTTPAuthMiddleware instead.
in settings.py:
DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware': 811,
}
in the spider:
from scrapy.spiders import CrawlSpider
class SomeIntranetSiteSpider(CrawlSpider):
http_user = 'someuser'
http_pass = 'somepass'
name = 'intranet.example.com'
# .. rest of the spider code omitted ...

Hello world of sprox with pyramid - part 2

I've tried to build the simplest possible form in Sprox using pyramid.
# model.py
class Allocation:
# some fields ...
class SproxForm(AddRecordForm):
__model__ = Allocation
sprox_form = SproxForm(DBSession)
# views.py
#view_config(route_name='sprox_add', renderer='templates/sprox.pt')
def sprox_form_add(request):
return {'form':sprox_form,'form_input':{}}
<!-- sprox.pt -->
<html>
<body>
<div tal:content="structure form(form_input)"/>
</body>
</html>
When I navigate to that view in the browser, I get
Traceback (most recent call last):
File "D:\prg\py2\lib\site-packages\pyramid_debugtoolbar-1.0.4-py2.7.egg\pyramid_debugtoolbar\panels\performance.py", line 69, in noresource_timer_handler
result = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\tweens.py", line 21, in excview_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 82, in tm_tween
reraise(*exc_info)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 63, in tm_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\router.py", line 161, in handle_request
response = view_callable(context, request)
File "D:\prg\py2\lib\site-packages\pyramid\config\views.py", line 367, in rendered_view
context)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 531, in render_view
return self.render_to_response(response, system, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 561, in render_to_response
result = self.render(value, system_values, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 557, in render
result = renderer(value, system_values)
File "D:\prg\py2\lib\site-packages\pyramid\chameleon_zpt.py", line 42, in __call__
result = self.template(**system)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 125, in __call__
return self.render(**kwargs)
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 257, in render
return super(PageTemplate, self).render(**vars)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 190, in render
raise_with_traceback(exc, tb)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 172, in render
self._render(stream, econtext, rcontext)
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 136, in render
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 261, in include
self._render(*args, **kwargs)
File "template_f352de36cd7e76f81188f12078004a91a152cf44.py", line 376, in render
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 106, in __fill_content
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 113, in __call__
return self.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 119, in display
return self.__widget__.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 438, in display
return self.generate_output(displays_on)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 475, in generate_output
mw,
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 204, in render
return callback(kwargs)
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 144, in <lambda>
return lambda kwargs: Markup(tmpl.render(**kwargs))
File "D:\prg\py2\lib\site-packages\mako\template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "form_mak", line 49, in render_body
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 436, in display
r.prepare()
File "D:\prg\py2\lib\site-packages\tw2\core\resources.py", line 165, in prepare
resources = rl['middleware'].resources
KeyError: 'middleware'
- Expression: "form(form_input)"
- Filename: d:\prg\py2\awsalloc2\awsalloc2\templates\sprox.pt
- Location: (9:28)
- Source: ... v tal:content="structure form(form_input)" />
^^^^^^^^^^^^^^^^
- Arguments: repeat: {...} (0)
renderer_name: templates/sprox.pt
req: <Request - at 0x46fceb8L>
form: <SproxForm - at 0x471cb38L>
request: <Request - at 0x46fceb8L>
renderer_info: <RendererHelper - at 0x4a3b7b8L>
context: <instance None at 0x4f93c88L>
form_input: {...} (0)
view: <function sprox_form_add at 0x4a3d278L>
I have no idea what your real problem is, but I threw together a little demo to demonstrate how to setup Sprox under Pyramid. It was somewhat painful and uses some idioms that I consider pretty outdated, including requiring Paste, SQLAlchemy < 0.8, Genshi, and ToscaWidgets < 2.0. Hope this helps.
If I had to guess, you aren't adding the middleware to your app.
app = tw.api.make_middleware(
app,
{
'toscawidgets.framework' : 'wsgi',
'toscawidgets.middleware.inject_resources' : True,
},
stack_registry=True,
)
https://github.com/mmerickel/pyramid_sprox_demo

Categories

Resources