coala / coala-bears

Bears for coala
https://coala.io/
GNU Affero General Public License v3.0
294 stars 580 forks source link

PySafetyBear broken by new release: TypeError: check() missing 1 required positional argument: 'proxy' #2857

Closed jayvdb closed 5 years ago

jayvdb commented 5 years ago

https://travis-ci.org/jayvdb/coala-bears/jobs/488802415

Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/coalib/bears/Bear.py", line 454, in execute
    return [] if result is None else list(result)
  File "/home/travis/build/jayvdb/coala-bears/bears/python/requirements/PySafetyBear.py", line 97, in run
    ignore_ids=cve_ignore):
TypeError: check() missing 1 required positional argument: 'proxy'
Naveenaidu commented 5 years ago

@jayvdb The above error occurs due to the recent change in the Safety package which has been release on 5th Feb (Today). The new version comes with the added functionality to support proxies which the Requests module of python uses. The new argument is now passed in safety.check(). And hence the addition of new positional argument.

The commit which made these changes is here

It is important to note that the proxy argument here is then passed onto Requests in safety.py. For more information about proxy please refer to the Requests Documentation- Proxy section

In order to fix the above Travis error we would now have to pass an additional argument called as proxy in the PySafetyBear at the line. The new safety.check() function should look like:

proxy = {}
 for vulnerability in safety.check(packages, key=None,
                                          db_mirror=db_path, cached=False,
                                          ignore_ids=cve_ignore, proxy=proxy):
if 'cve' in vulnerability.vuln_id.strip().lower(): 

The argument proxy is a dictionary datatype which holds values something like:

proxies = {
  "http": "10.10.1.10:3128",
  "https": "10.10.1.10:1080",
}

Since we don't use any proxies, I guess we can leave it as a empty dictionary like proxy = {}

The reference for the above thing is taken from StackOverflow and Requests Docs

The tests for the above new argument can be found at test_safety of the Safety library.

jayvdb commented 5 years ago

Since we don't use any proxies, I guess we can leave it as a empty dictionary like proxy = {}

Yup, that is what we should do.

It might also be possible to set proxy=None, and that would be preferred way to indicate no proxy are requested.