Python Forum

Full Version: what is wrong with this code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Smile

I made a python script to take data from a file, visit a web site using the data in the request, and save a specific text returned from the site in another file.

But I'm getting a TypeError: 'str' object is not callable and don't know how to solve it.

PS: I'm still learning python, and this is the first script I ever made.


from urllib.request import urlopen
import requests
 # for Python 3: from urllib.request import urlopen
from bs4 import BeautifulSoup
import os
import urllib.request


#x=open("demofile.txt", "r")
#with open('demofile.txt', 'r') as fx:
#   for line in fx
     
with open('demofile.txt', 'r') as fx:

 for lines in fx.readlines():
  with urllib.request.urlopen('http://api1.5sim.net/stubs/handler_api.php?api_key=XXXXXXX&action=getStatus&id='+lines) as data:
   soup = BeautifulSoup(data.read(),'lxml').text
   xt =soup.split(':')[1]
   with open ('pin.txt','w')as writer:
     for pins in xt:
	     writer.writelines(pins)
   print(xt)
   
markayala Wrote:I'm getting a TypeError: 'str' object is not callable and don't know how to solve it.
It is important that you post the whole error message that python prints in the console. This error message contains crucial information as to where exactly the error occurs in the code. If you want good help, please post everything after "Traceback, most recent call last ..."