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

Cannot use API with default urllib #297

Closed
miracle2k opened this issue Oct 4, 2013 · 8 comments
Closed

Cannot use API with default urllib #297

miracle2k opened this issue Oct 4, 2013 · 8 comments
Labels
bug Something isn't working outdated Request fallen into oblivion
Milestone

Comments

@miracle2k
Copy link
Contributor

>>> from urllib import urlencode; from urllib2 import urlopen; urlopen('http://localhost:8000/api/login', urlencode({'a': 1}))
urllib2.HTTPError: HTTP Error 500: Internal Server Error

Strangly, it works using requests:

>>> import requests; requests.post('http://dollhouse:8000/api/login')
<Response [200]>

It turns out that this is because urllib2 only sets this Accpet-Encoding header:

Accept-Encoding: identity

Things look better when I add gzip manually:

>>> import urllib2; headers = { 'Accept' : '*/*', 'Accept-Encoding': 'identity, gzip'}; re = urllib2.Request('http://localhost:8000/api/login', "", headers); urllib2.urlopen(re)
<addinfourl at 41238752 whose fp = <socket._fileobject object at 0x27466d0>>

I should say that I am using pyload as packaged by http://spk.unzureichende.info/ for Synology, using 0.4.9-4.

@stickell
Copy link
Contributor

stickell commented Oct 4, 2013

It works for me with urllib, I haven't tried urllib2

@miracle2k
Copy link
Contributor Author

This is an example of a HTTP request that returns a 500 error on my PyLoad installation:

POST /api/login HTTP/1.1
Accept-Encoding: identity
Content-Length: 3
Host: localhost:8000
Content-Type: application/x-www-form-urlencoded
Connection: close
User-Agent: Python-urllib/2.7

 a=1

Note that the error is not related to the dummy POST data.

@stickell
Copy link
Contributor

stickell commented Oct 4, 2013

This code always worked for me:

import json
import urllib

u = 'http://localhost:8000/api/login'
post_data = urllib.urlencode({'username': 'user', 'password': 'pwd'})
rep = urllib.urlopen(u, post_data).read()
SESSION_ID = json.loads(rep)

@miracle2k
Copy link
Contributor Author

Note that I I'm not looking for a solution, I can get it working by sending HTTP requests that accept a gzipped response. I just wanted to report this as an issue, in case it is one.

If my error is reproducible on a standard PyLoad installation, I think it should be fixed. Otherwise, it might be an issue with the way my PyLoad has been packaged for Synology.

@stickell
Copy link
Contributor

stickell commented Oct 7, 2013

We can't fix it in 0.4.9 because it is frozen, if 0.5 is affacted I'm sure @RaNaN will fix it.

@vuolter vuolter removed the feedback wanted User attention is needed label Oct 22, 2014
@stale
Copy link

stale bot commented May 3, 2019

This ticket has been automatically marked as inactive because 90 days have passed since the last comment.
It will be closed in 7 days if no further activity occurs.
If this issue still requires attention, please leave a comment.

@stale stale bot added the outdated Request fallen into oblivion label May 3, 2019
@stale
Copy link

stale bot commented May 10, 2019

This ticket has been automatically closed.
This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable.
Feel free to open a new issue if you deem it appropriate. Don't forget to reference this to the new one.
Thanks for your contributions.

@stale stale bot closed this as completed May 10, 2019
@github-actions
Copy link

This ticket has been automatically locked since there has not been any recent activity after it was closed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated Request fallen into oblivion
Development

No branches or pull requests

3 participants