Python TypeError

Ok, so these lines usually work fine, but sometime produce type error (the bold part is producing it).
 1228         url = "" % params
 1229        [b] output = getPage(""\
 1230         % urllib.urlencode({'longUrl':url}))[:22].replace("http://", "")[/b]

Open in new window

TypeError: unsubscriptable object
      args = ('unsubscriptable object',)

Also in debug report, when this error occured both params and url variables were setup fine. HELP!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You should copy/paste our error message with the trace.
GVNPublic123Author Commented:
But I gave you traced line of code and error...what more do you need? There aint no more in report.
How do you run it?  Is it a part of some web server code?  Where the 'args = ...' came from?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

GVNPublic123Author Commented:
No idea...its just a random python fail.
GVNPublic123Author Commented:
It occured, but I cant recreate it. I put exception handling for next time.
How do you run your Python code?  Is it saved in a file and launched say from command line?  How do you know that the mentioned line caused the error?  What version of Python do you use?  What OS do you use?
GVNPublic123Author Commented:
CentOS 5, its a website, python 2.4.3

Got it from bug report.
OK.  I cannot help too much here.  If you know it was the line
1229  output = getpage(...)[:22].replace("http://", "")[/b]

Open in new window

The error generally means that you try to index/slice what cannot be indexed -- i.e. the object you probably got cannot be sliced using the [:22].  It is likely that the getpage() returned None as the error result or something like that.

Try to avoid that kind of method chaining if the code is a bit complex and if it can fail:
    output = ''         # or some better initial value
    page = getpage(...)
    if page:              # or some more explicit testing
        output = page[:22].replace(...)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GVNPublic123Author Commented:
Yeh, I put exception handling in so now I dont care if slicing fails. The worker will pick it up later automatically if it fails on request.
Sorry I could not be more explicit.  Thanks for the points, and have a good time ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.