[issue9668] strings in json.dump in '' instead of ""

2010-08-24 Thread Jordan Szubert

Jordan Szubert  added the comment:

could not reproduce:

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from cStringIO import StringIO as F
>>> import json
>>> json.dumps('foo')
'"foo"'
>>> f=F()
>>> json.dump('foo',f)
>>> f.seek(0,0);f.read();f.seek(0,0)
'"foo"'
>>> json.dump({'a':['b']},f)
>>> f.seek(0,0);f.read();f.seek(0,0)
'{"a": ["b"]}'
>>> 


Python 2.6.5+ (release26-maint, Jul 30 2010, 23:04:10)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> from cStringIO import StringIO as F
>>> f=F()
>>> json.dump('foo',f)
>>> json.dumps('foo')
'"foo"'
>>> f.seek(0,0);f.read();f.seek(0,0)
'"foo"'
>>> json.dump({'a':1,'_':2},f)
>>> f.seek(0,0);f.read();f.seek(0,0)
'{"a": 1, "_": 2}'
>>> json.dumps({'a':1,'_':2})
'{"a": 1, "_": 2}'
>>>

--
nosy: +joru

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



[issue18229] attribute headers of http.server.BaseHTTPRequestHandler sometimes does not exists

2013-06-16 Thread Jordan Szubert

New submission from Jordan Szubert:

it seems that problem is someone connecting to port 8080 with non-http client, 
could not find warning in documentation


---fragment of `less access.log`
81.172.30.254 - - [16/Jun/2013 11:36:58] "^SBitTorrent protocol^@^@^@^@^@^X^@^Ej
81.172.30.254 - - [16/Jun/2013 11:38:11] "^N^@f¸ãÄòQ;³xb^C^HÄA7
81.172.30.254 - - [16/Jun/2013 11:39:22] "^SBitTorrent protocol^@^@^@^@^@^X^@^Ej
81.172.30.254 - - [16/Jun/2013 11:40:35] "ì0æzzr^D2]WQ



Exception happened during processing of request from ('81.172.30.254', 63650)
Traceback (most recent call last):
  File "c:\Python33\lib\socketserver.py", line 306, in _handle_request_noblock
self.process_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 332, in process_request
self.finish_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 345, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "c:\Python33\lib\socketserver.py", line 666, in __init__
self.handle()
  File "c:\Python33\lib\http\server.py", line 400, in handle
self.handle_one_request()
  File "c:\Python33\lib\http\server.py", line 380, in handle_one_request
if not self.parse_request():
  File "c:\Python33\lib\http\server.py", line 283, in parse_request
self.send_error(400, "Bad request version (%r)" % version)
  File "c:\Python33\lib\http\server.py", line 428, in send_error
self.send_response(code, message)
  File "c:\Python33\lib\http\server.py", line 443, in send_response
self.log_request(code)
  File "c:\Users\joru\Dropbox\programowanie\demoniszcze\server\_lowerHTTP.py", 
line 30, in log_request
xff=req.headers.get('X-Forwarded-For')
AttributeError: '_HNDL_3' object has no attribute 'headers'
# _HNLD_3 derives from http.server.BaseHTTPRequestHandler

--
assignee: docs@python
components: Documentation
messages: 191264
nosy: docs@python, joru
priority: normal
severity: normal
status: open
title: attribute headers of http.server.BaseHTTPRequestHandler sometimes does 
not exists
type: behavior
versions: Python 3.3

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



[issue18229] attribute headers of http.server.BaseHTTPRequestHandler sometimes does not exists

2013-10-06 Thread Jordan Szubert

Jordan Szubert added the comment:

what _lowerHTTP does is try read request header 'X-Forwarded-For', but instance 
of request handler have attribute headers only if thing that connected to port 
where server listens happened to send valid enough http request

my problem is, documentation does not help write code that would not crash when 
client sends random bytes instead of expected http request

--
resolution: invalid -> 
status: closed -> open

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



[issue18229] attribute headers of http.server.BaseHTTPRequestHandler sometimes does not exists

2013-10-06 Thread Jordan Szubert

Jordan Szubert added the comment:

#minimal server:
#!/c/Python33/python.exe
from http.server import HTTPServer as S, BaseHTTPRequestHandler as H
class HNDL(H):
def log_request(req,code):
print('header is',req.headers.get('X-Forwarder-For'),', 
code',code)
H.log_request(req)
s=S(('',54321),HNDL)
s.serve_forever()


#non-http client:
#!/c/Python33/python.exe
import socket,os
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 54321))
s.sendall(os.urandom(1024))
buf=s.recv(2048)
s.close()
print(buf)


#running server:
$ ./server.py
127.0.0.1 - - [06/Oct/2013 17:33:41] code 400, message Bad HTTP/0.9 request type
 ('E)\xaeE^2¤\xf2W\x8f\xb3aG')

Exception happened during processing of request from ('127.0.0.1', 18234)
Traceback (most recent call last):
  File "c:\Python33\lib\socketserver.py", line 306, in _handle_request_noblock
self.process_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 332, in process_request
self.finish_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 345, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "c:\Python33\lib\socketserver.py", line 666, in __init__
self.handle()
  File "c:\Python33\lib\http\server.py", line 400, in handle
self.handle_one_request()
  File "c:\Python33\lib\http\server.py", line 380, in handle_one_request
if not self.parse_request():
  File "c:\Python33\lib\http\server.py", line 311, in parse_request
"Bad HTTP/0.9 request type (%r)" % command)
  File "c:\Python33\lib\http\server.py", line 428, in send_error
self.send_response(code, message)
  File "c:\Python33\lib\http\server.py", line 443, in send_response
self.log_request(code)
  File "./server.py", line 5, in log_request
print('header is',req.headers.get('X-Forwarder-For'),', code',code)
AttributeError: 'HNDL' object has no attribute 'headers'



#running client:
$ ./client.py
b''
$

--

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