jsumners / jsumners/feedparser

authentication creds are not used

Open
#283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-migrated
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

I'm using feedparser-5.0.1-py2.6 , tried on CentOS and Windows. I'm having 
trouble accessing feeds protected by HTTP Basic Auth using the documented "hard 
way". This may be related to Issue 267, but my case is more basic.

Here's the first failure (please substitute your own known good URL/realm):

>>> import feedparser, urllib2
>>> url = 'https://example.com/news/feed/service'
>>> auth = urllib2.HTTPBasicAuthHandler()
>>> auth.add_password('*** realm ***', 'https://example.com', '*** username 
***', '*** password ***')
>>> f = feedparser.parse(url, handlers=[auth])
>>> f.status
401
>>> f.entries
[]

Authentication failed! I expect status to be 200 and there to be some entries 
in the list. I skimmed the relevant source code and found a custom 
urllib2.Request factory (_build_urllib2_request) along with the custom 
_FeedURLHandler() object. I made some low-level calls and found something 
interesting: I can authenticate successfully if I use one of those two 
customizations, but not both:

>>> def test(request, opener):
...   opener.addheaders = []
...   f = opener.open(request)
...   f.read()
...   result = f.status if hasattr(f, 'status') else 'success'
...   f.close()
...   return result

# Use urllib2 standards
>>> request = urllib2.Request(url)
>>> opener = urllib2.build_opener(auth)
>>> test(request, opener)
'success'

# Use only _FeedURLHandler
>>> request = urllib2.Request(url)
>>> opener = apply(urllib2.build_opener, tuple([auth] + 
[feedparser._FeedURLHandler()]))
>>> test(request, opener)
'success'

# Use only _build_urllib2_request
>>> request = feedparser._build_urllib2_request(url, None, None, None, None, 
None, {})
>>> opener = urllib2.build_opener(auth)
>>> test(request, opener)
'success'

# Use both, as feedparser.parse() does
>>> request = feedparser._build_urllib2_request(url, None, None, None, None, 
None, {})
>>> opener = apply(urllib2.build_opener, tuple([auth] + 
[feedparser._FeedURLHandler()]))
>>> test(request, opener)
401

Is this a bug? Hope to use a released version of your software instead of 
hacking it. Thanks.

Original issue reported on code.google.com by tra...@gmail.com on 7 Jun 2011 at 11:39

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with feedparser._build_urllib2_request and _FeedURLHandler(), which the report identifies as interacting incorrectly with urllib2 authentication handlers. Reproduce the supplied four opener/request combinations and verify that feedparser.parse() returns status 200 with entries for the authenticated feed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.