Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7614311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:22:19+00:00 2026-05-31T02:22:19+00:00

I’m trying to write a python script that sends a query to TweetSentiments.com API.

  • 0

I’m trying to write a python script that sends a query to TweetSentiments.com API.

The idea is that it will perform like this –
Reads CSV tweet file > construct query > Interrogates API > format JSON response > writes to CSV file.

So far I’ve come up with this –

import csv
import urllib
import os

count = 0

TweetList=[] ## Creates empty list to store tweets.

TweetWriter = csv.writer(open('test.csv', 'w'), dialect='excel', delimiter=' ',quotechar='|')
TweetReader = csv.reader(open("C:\StoredTweets.csv", "r"))

for rows in TweetReader:

    TweetList.append(rows)

#print TweetList [0]

for rows in TweetList:

    data = urllib.urlencode(TweetList[rows])
    connect = httplib.HTTPConnection("http://data.tweetsentiments.com:8080/api/analyze.json?q=")
    connect.result = json.load(urllib.request("POST", "", data))
        TweetWriter.write(result)

But when its run I get “line 20, data = urllib.urlencode(TweetList[rows]) Type Error: list indices must be integers, not list”

I know my list “TweetList” is storing the tweets just as I’d like but I don’t think I’m using urllib.urlencode correct. The API requires that queries are sent like –

http://data.tweetsentiments.com:8080/api/analyze.json?q= (text to analyze)

So the idea was that urllib.urlencode would simply add the tweets to the end of the address to allow a query.

The last four lines of code have become a mess after looking at so many examples. Your help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:22:20+00:00Added an answer on May 31, 2026 at 2:22 am

    I’m not 100% sure what it is you’re trying to do since I don’t know what’s the format of the files you are reading, but this part looks suspicious:

    for rows in TweetList:
        data = urllib.urlencode(TweetList[rows])
    

    since TweetList is a list, the for loop puts in the rows one single value from the list in each iteration, and so this for example:

    list = [1, 2, 3, 4]
    for num in list:
        print num
    

    will print 1 2 3 4. But if this:

    list = [1, 2, 3, 4]
    for num in list:
        print list[num]
    

    Will end up with this error: IndexError: list index out of range.

    Can you please elaborate a bit more about the format of the files you are reading?


    Edit

    If I understand you correctly, you need something like this:

    tweets = []
    tweetReader = csv.reader(open("C:\StoredTweets.csv", "r"))
    
    for row in tweetReader:
        tweets.append({ 'tweet': row[0], 'date': row[1] })
    
    for row in tweets:
        data = urllib.urlencode(row)
        .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python script that takes record data like this
I'm trying to write a small Python script that will get query results from
I'm trying to write a python script that packages our software. This script needs
I am trying to write a Python script that will access and modify the
I am trying to write a Python script that will copy files from one
I am trying to write a python script that will SSH to a server
I am trying to write a Python script that will list all of my
I'm trying to write a Python script that will enable me to start the
I am trying to write out a python cgi script that will redirect me
I'm trying to write a Python script that will get the md5sum of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.