Something like this should work:
request = Request.blank(“/“, POST={“foo”: “bar”})
with pyramid.scripting.prepare(registry=app.registry, request=request):
...
— Theron
> On Mar 25, 2025, at 1:49 PM, Jonathan Vanasco <[email protected]> wrote:
>
> Michael- one more question:
>
> Do you know if there is better way to stuff POST/GET vars in this context
> than the following?
>
> > request.environ["REQUEST_METHOD"] = "POST"
> > wsgi_input = BytesIO(b"")
> > request.body_file_raw = wsgi_input
> > request.environ["webob._parsed_post_vars"] = (options, wsgi_input)
>
> This is leveraging (abusing) the `webob._parsed_post_vars` storage and a
> check against `.body_file_raw`
>
>
> On Tuesday, March 25, 2025 at 3:37:58 PM UTC-4 Michael Merickel wrote:
>> The request factory doesn't fully do every step of initializing a request
>> since it's a user-overridable hook. It's not really intended to be used
>> directly. To have a fully initialize request you later need to do a couple
>> steps iirc.
>>
>> 1. request.registry = app.registry
>> 2. pyramid.request.apply_request_extensions(request)
>>
>> This is off the top of my head so I may be forgetting a step, apologies but
>> hopefully this is helpful.
>>
>> The "right" way to do this is to use pyramid.scripting.prepare:
>>
>> with pyramid.scripting.prepare(registry=app.registry) as env:
>> request = env['request']
>>
>> On Tue, Mar 25, 2025 at 12:27 PM Jonathan Vanasco <[email protected] <>>
>> wrote:
>>> I can't seem to generate a request properly.
>>>
>>> For example, in `main(`:
>>>
>>> from pyramid.interfaces import IRequestFactory
>>> from pyramid.request import Request
>>>
>>> app = config.make_wsgi_app()
>>> request_factory = app.registry.queryUtility(IRequestFactory,
>>> default=Request)
>>> request = request_factory.blank("/")
>>>
>>> The query for IRequestFactory always returns None, leaving me with the
>>> default `Request` (which has none of the configured `add_request_method`
>>> attributes)
>>>
>>> I've also tried this using `get_app(config_uri)` from scripting.
>>>
>>> Am I querying the wrong interface, or is this just not a compatible
>>> use-case?
>>>
>>>
>>>
>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "pylons-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected] <>.
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/pylons-discuss/c46029eb-e0c4-4f75-82d1-2971f55a49bcn%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/pylons-discuss/c46029eb-e0c4-4f75-82d1-2971f55a49bcn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>>
>>
>> --
>>
>> Michael
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion visit
> https://groups.google.com/d/msgid/pylons-discuss/ca785f12-2b6c-4f64-9f05-3809058987ecn%40googlegroups.com
>
> <https://groups.google.com/d/msgid/pylons-discuss/ca785f12-2b6c-4f64-9f05-3809058987ecn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/pylons-discuss/8799F2ED-D211-4921-B84C-32A3F783A208%40luhn.com.