New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webob.Response.from_file parsing failure #250

Closed
rtilder opened this Issue May 19, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@rtilder

rtilder commented May 19, 2016

webob.Request's from_file method seems have to an incorrect call to str.split()

    import io, webob
    s = "HTTP/1.0 200 Ok\nConnection: close\n\n"
    webob.Request.from_file(io.BytesIO(s))  # success
    s = "HTTP/1.0 404 Not Found\nConnection: close\n\n"
    webob.Request.from_file(io.BytesIO(s))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/rtilder/sandbox/horked_from_file/lib/python2.7/site-packages/webob/response.py", line 179, in from_file
        (http_ver, status_num, status_text) = status.split()
    ValueError: too many values to unpack

Relevant code is here. The existing code works just fine on a 200 response but not on the faux 404

(http_ver, status_num, status_text) = status.split()

I suspect that this is inadvertent and that the following was probably intended.

(http_ver, status_num, status_text) = status.split(None, 2)

I was a little surprised I ran into this until I realized that parsing HTTP responses is probably not a terribly common use case.

@mmerickel

This comment has been minimized.

Show comment
Hide comment
@mmerickel

mmerickel May 19, 2016

Member

You're parsing responses and linked to webob.response code but your code example uses Request.from_file. Is that actually correct?

Member

mmerickel commented May 19, 2016

You're parsing responses and linked to webob.response code but your code example uses Request.from_file. Is that actually correct?

bertjwregeer added a commit that referenced this issue May 20, 2016

@bertjwregeer

This comment has been minimized.

Show comment
Hide comment
@bertjwregeer

bertjwregeer May 20, 2016

Member

Request.from_file is doing the right thing: https://github.com/Pylons/webob/blob/master/webob/request.py#L1208

I've fixe this issue in 17e170d and added a test in 9aae43c so this can't regress.

Thanks for reporting. I'll back port this to 1.6 this weekend.

Member

bertjwregeer commented May 20, 2016

Request.from_file is doing the right thing: https://github.com/Pylons/webob/blob/master/webob/request.py#L1208

I've fixe this issue in 17e170d and added a test in 9aae43c so this can't regress.

Thanks for reporting. I'll back port this to 1.6 this weekend.

@rtilder

This comment has been minimized.

Show comment
Hide comment
@rtilder

rtilder May 20, 2016

Sorry about the mispasted code. webob.Request.from_file parsing correctly, yes. webob.Response.from_file fails. Thanks for the quick fix.

rtilder commented May 20, 2016

Sorry about the mispasted code. webob.Request.from_file parsing correctly, yes. webob.Response.from_file fails. Thanks for the quick fix.

@bertjwregeer bertjwregeer changed the title from webob.Request.from_file parsing failure to webob.Response.from_file parsing failure May 20, 2016

bertjwregeer added a commit that referenced this issue May 20, 2016

bertjwregeer added a commit that referenced this issue May 20, 2016

Split on first two whitespaces in Response.from_file
This fixes #250 by not attempting to split the entire string. This is
required for any status codes that are not just <number> <one word
status text>

Things like 404 Not Found or 402 Payment Required.

bertjwregeer added a commit that referenced this issue May 20, 2016

bertjwregeer added a commit that referenced this issue May 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment