Skip to content
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
Closed

webob.Response.from_file parsing failure #250

rtilder opened this issue May 19, 2016 · 3 comments
Milestone

Comments

@rtilder
Copy link

@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
Copy link
Member

@mmerickel 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
Copy link
Member

@bertjwregeer 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
Copy link
Author

@rtilder 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 webob.Request.from_file parsing failure 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
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.