0

I'm just starting with PyDev but struggling to understand how to manage its error reporting.

For example, I have added bottle.py to my project's External Libs, and added 'bottle' to the Python Interpreter configuration Packages and Forced Builtins tabs. However, in a file containing just the following code, the 5th line shows 2 errors: "Undefined variable from import: request" and "Undefined variable from import: get". The 3rd line is ok.

from bottle import request
def postd():
    return request.forms
def post_get(name, default=''):
    return request.POST.get(name, default).strip()

Why is PyDev reporting errors in line 5? How do I remedy this?

dls49
  • 67
  • 7
  • 1
    Possible duplicate of [How do I fix PyDev "Undefined variable from import" errors?](https://stackoverflow.com/questions/2112715/how-do-i-fix-pydev-undefined-variable-from-import-errors) – vinS Jan 04 '18 at 02:34

1 Answers1

0

The problem is that PyDev does an introspection when you add it to the forced builtins, but bottle doesn't work directly like that.

i.e.: if you open a shell and do:

from bottle import request
dir(request.POST)

you have an error (and this prevents PyDev from properly analyzing that module):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 166, in __get__
    if key not in storage: storage[key] = self.getter(obj)
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 1218, in POST
    pairs = _parse_qsl(tonat(self._get_body_string(), 'latin1'))
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 1185, in _get_body_string
    data = self.body.read(clen)
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 1197, in body
    self._body.seek(0)
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 166, in __get__
    if key not in storage: storage[key] = self.getter(obj)
  File "C:\tools\Miniconda\envs\check\lib\site-packages\bottle.py", line 1164, in _body
    read_func = self.environ['wsgi.input'].read
KeyError: 'wsgi.input'

Solutions include creating your own wrapper for that in your own code and at that place notifying that this is expected (Ctrl+1 in that line will show an option to ignore that error in a specific line) -- How do I fix PyDev "Undefined variable from import" errors? has other fixes.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • Thanks @Fabio Zadrozny, for explaining how that error arises. In a solution using a wrapper what does the wrapper have to do to notify this is expected? Does it just move the option to ignore to another place? Can you please give an example to illustrate this solution. – dls49 Jan 05 '18 at 04:05