使用python请求访问qube-Webapi
我对pyhton非常陌生。我只是尝试了一种简单的方法,用python从SonarWebAPI获取一个使用python请求访问qube-Webapi,python,sonarqube,python-requests,Python,Sonarqube,Python Requests,我对pyhton非常陌生。我只是尝试了一种简单的方法,用python从SonarWebAPI获取一个HTTP响应 我使用请求库并尝试一个简单的用法: project = requests.get(url=Sonar_Api_Projects_Search, params=param_Projects, verify=False, headers={'Authorization': 'token {}'.format(token)}) 当我在e web浏览器中使用它时,请求格式良好,工作正常 但
HTTP
响应
我使用请求库并尝试一个简单的用法:
project = requests.get(url=Sonar_Api_Projects_Search, params=param_Projects, verify=False, headers={'Authorization': 'token {}'.format(token)})
当我在e web浏览器中使用它时,请求格式良好,工作正常
但作为回应,我得到了一个奇怪的结果:
{“err_code”:500,“err_msg”:“未定义的方法empty?”用于
nil:NilClass\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/lib/authenticated\u system.rb:132:in
login\u from\u basic\u auth'\n\torg/jruby/RubyProc.java:290:in
call'\n\torg/jruby/RubyProc.java:224:in
call'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/http\u authentication.rb:126:in
authenticate'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/http\u authentication.rb:116:in
authenticate\u与\u http\u basic'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/lib/authenticated\u system.rb:129:in
login\u from\u basic\u auth'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/lib/authenticated\u system.rb:11:in
current\u user'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/app/controllers/application\u controller.rb:102:inset\u user\u session'\n\torg/jruby/RubyKernel.java:2223:in
send'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activesupport-2.3.15/lib/active\u support/callbacks.rb:178:in
evaluate_method'\n\tD:/sonarqube-5.6.6_20170214/web/web-INF/gems/gems/activesupport-2.3.15/lib/active_-support/callbacks.rb:166:in
call'\n\tD:/sonarqube-5.6.6_20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:225:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/filters.rb:629:in
run\u before\u filters'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/filters.rb:615:in
call_filters'\n\tD:/sonaqube-5.6.6_20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action_controller/filters.rb:610:in
使用过滤器执行动作\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/benchmarking.rb:68:in
使用“基准”执行“操作”\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activesupport-2.3.15/lib/active\u support/core\u ext/benchmark.rb:17:in
ms'\n\tjar:file:/D:/sonaqube-5.6.6\u 20170214/lib/server/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/benchmark.rb:308:in
realtime'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activesupport-2.3.15/lib/active\u support/core\u ext/benchmark.rb:17:in
ms'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/benchmarking.rb:68:in
使用基准“\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/rescue.rb:160:in
perform\u action\u with\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/flash.rb:151:inperform\n\torg/jruby/RubyKernel.java:2223:in
send'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/base.rb:532:in
process'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/filters.rb:606:in
process_with_filters'\n\tD:/sonarqube-5.6.6_20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action_controller/base.rb:391:in
process'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/base.rb:386:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/routing/route\u set.rb:450:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/dispatcher.rb:87:in
dispatch'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/dispatcher.rb:85:in
dispatch'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/dispatcher.rb:121:in
\u调用'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/dispatcher.rb:130:in
build\u middleware\u stack'\n\torg/jruby/RubyProc.java:290:in
call'\n\torg/jruby/RubyProc.java:224:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activerecord-2.3.15/lib/active\u record/query\u cache.rb:29:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activerecord-2.3.15/lib/active\u record/connection\u adapters/abstract/query\u cache.rb:34:in
cache'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activerecord-2.3.15/lib/active\u record/query\u cache.rb:9:in
cache'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activerecord-2.3.15/lib/active\u record/query\u cache.rb:28:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/activerecord-2.3.15/lib/active\u record/connection\u adapters/abstract/connection\u pool.rb:361:in
call'\n\tD:/sonaqube-5.6.6_20170214/web/web-INF/config/environment.rb:67:in
call'\n\tD:/sonarqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/string\u胁迫。rb:25:in
call'\n\tD:/sonaqube-5.6.6_20170214/web/web-INF/gems/gems/rack-1.1.6/lib/rack/head.rb:9:incall'\n\tD:/sonaqube-5.6.6_20170214/web/web-INF/gems/gems/rack-1.1.6/lib/rack/methodoverride.rb:24:in
call'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/actionpack-2.3.15/lib/action\u controller/params\u parser.rb:15:in
call'\n\t文件:/D:/sonarqube-5.6.6\u 20170214/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session\u store.rb:70:in
context'\n\tD:/sonaqube-5.6.6\u 20170214/web/web-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/
import json , requests, pprint
url = 'http://sonar_url:9000/api/projects/search'
myToken = 'fa2377941a95125443f4efade615512jjkd221211a48'
session = requests.Session()
session.auth = myToken, ''
call = getattr(session, 'get')
res = call(url)
print(res.status_code)
binary = res.content
output = json.loads(binary)
pprint.pprint(output)
...
#Parse json result