Open azenakhi opened 8 years ago
The error is correct, you are not calling it from application context, the following code works for me:
with app.app_context():
see_json()
def see_json():
urlvars = False # Build query strings in URLs
swagger = True # Export Swagger specifications
data = api.as_postman(urlvars=urlvars, swagger=swagger)
f = open('postman_import.json', 'w')
f.write(json.dumps(data))
Thank you. It works
On Tuesday, 8 November 2016, artonio notifications@github.com wrote:
The error is correct, you are not calling it from application context, the following code works for me: `with app.app_context(): see_json()
def see_json(): urlvars = False # Build query strings in URLs swagger = True # Export Swagger specifications data = api.as_postman(urlvars=urlvars, swagger=swagger) f = open('postman_import.json', 'w') f.write(json.dumps(data))`
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/noirbizarre/flask-restplus/issues/208#issuecomment-259227898, or mute the thread https://github.com/notifications/unsubscribe-auth/AD74IRKhqSEAPm1HX24PwrEMeXfM--Ejks5q8MeGgaJpZM4KU2R2 .
Sent from Gmail Mobile
Hello,
I wanted to export API as a Postman but I have the following error:
File "test2.py", line 18, in
data = api.as_postman()
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/api.py", line 623, in as_postman
return PostmanCollectionV1(self, swagger=swagger).as_dict(urlvars=urlvars)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 187, in as_dict
Traceback (most recent call last):
File "test2.py", line 18, in
'id': self.id,
data = api.as_postman()
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 154, in id
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/api.py", line 623, in as_postman
return str(self.uuid)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 150, in uuid
return uuid5(NAMESPACE_URL, self.api.base_url)
return PostmanCollectionV1(self, swagger=swagger).as_dict(urlvars=urlvars)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/api.py", line 432, in base_url
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 187, in as_dict
'id': self.id,
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 154, in id
return str(self.uuid)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/postman.py", line 150, in uuid
return uuid5(NAMESPACE_URL, self.api.base_url)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/flask_restplus-0.9.2-py2.6.egg/flask_restplus/api.py", line 432, in base_url
return url_for(self.endpoint('root'), _external=True)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/Flask-0.11.1-py2.6.egg/flask/helpers.py", line 269, in url_for
return url_for(self.endpoint('root'), _external=True)
File "/home/zenakad/cdaas-api/lib/lib/python2.6/site-packages/Flask-0.11.1-py2.6.egg/flask/helpers.py", line 269, in url_for
raise RuntimeError('Attempted to generate a URL without the '
RuntimeError: raise RuntimeError('Attempted to generate a URL without the '
Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
RuntimeError: Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
My script
!/usr/bin/env python
from flask import Flask, json, url_for from flask_restplus import Resource, Api
app = Flask(name) api = Api(app)
@api.route('/hello') class HelloWorld(Resource): def get(self): return {'hello': 'world'}
if name == 'main': app.run(host='0.0.0.0', debug=True) app.config['SERVER_NAME'] = 'http://dev-cdaas.sws.group.gca:5000/todos' urlvars = False # Build query strings in URLs swagger = True # Export Swagger specifications data = api.as_postman(urlvars=urlvars, swagger=swagger) print(json.dumps(data))
best regards