[issue27777] cgi.FieldStorage can't parse simple body with Content-Length and no Content-Disposition

2016-08-16 Thread rr-

New submission from rr-:

Sending requests with Content-Length but without Content-Disposition headers 
causes following error:

Traceback (most recent call last):
  File "./test", line 19, in 
form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
  File "/usr/lib/python3.5/cgi.py", line 561, in __init__
self.read_single()
  File "/usr/lib/python3.5/cgi.py", line 740, in read_single
self.read_binary()
  File "/usr/lib/python3.5/cgi.py", line 762, in read_binary
self.file.write(data)
TypeError: write() argument must be str, not bytes

I've attached a test file that reproduces the issue.

The issue is because read_single decides whether to read the content as binary 
or text depending on content-length - if it's > 0, it uses read_binary which 
assumes binary input, and rewrites this input to self.file, assuming self.file 
is opened in binary mode.

At the same, self.file is opened in text mode, because self._binary_file is set 
to False, which in turn is because there's no Content-Disposition header.

At very least, the decision whether to use binary or text should be consistent 
in both places (self.length >= 0 vs self._binary_file).

Related: https://bugs.python.org/issue27308
Note that unlike https://bugs.python.org/issue24764 this issue does NOT concern 
multipart requests.

------
components: Library (Lib)
files: test
messages: 272856
nosy: rr-
priority: normal
severity: normal
status: open
title: cgi.FieldStorage can't parse simple body with Content-Length and no 
Content-Disposition
versions: Python 3.5
Added file: http://bugs.python.org/file44124/test

___
Python tracker 
<http://bugs.python.org/issue2>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40202] Misleading grammatically of ValueError Message?

2020-04-06 Thread Jacob RR


New submission from Jacob RR :

hi,

so I *think* that ValueError shows an error grammatically incorrect?
In python 2.7
>>> x = [1,2,3]
>>> f,x, a, b = [1,2,3]
Traceback (most recent call last):
  File "", line 1, in 
ValueError: need more than 3 values to unpack

Should have said: Received 3 values to unpack ?
The problem with that is the list size is 3 and the error says that I need more 
than 3 values to unpack which is logically wrong **IMHO** (don't kill me if im 
mistaken)

Now if I try to do something else, for example:

>>> x = [1,2,3]
>>> a, b = [1,2,3]

Traceback (most recent call last):
  File "", line 1, in 
ValueError: too many values to unpack

It says **too many** but I assign a few than the size of the list. am I the one 
who wrong here?

Now, I code in Python 3 I'm not a professional  like you, I'm novice and try to 
learn.. I'll get to the point, the same code in Python 3.7.6 (Anaconda, pip is 
disappoint me :< )

>>> a = [1,2,3]
>>> x,y = a
Traceback (most recent call last):
  File "", line 1, in 
ValueError: too many values to unpack (expected 2)

Should said something else because it received less values and expected should 
say 3 and not 2, correct?


thanks for reading.




PS: Sorry I'm not a native speaker and I might be wrong and am very sorry if 
time wasted.

--
assignee: docs@python
components: Documentation
messages: 365842
nosy: Jacob RR, docs@python
priority: normal
severity: normal
status: open
title: Misleading grammatically of ValueError Message?
type: enhancement
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue40202>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com