Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 visibility/space of variables. Pls help.
#1
I have two modules only.
the first one - is the main programm, which is using functions from the second module.
The second module consists from functions only
Here is the first module
import requests
from bs4 import BeautifulSoup
import sys
sys.path.append("E:\\Python\\Learning\\Parce_functions")
spisok = []         
_tmpvar = ""        
import F_Hydac_POST
_name_element = "pi3111"
spisok = F_Hydac_POST.start_parce(_name_element)
print("Here is the Hydac list", spisok)
here is the second module
 
def fg_list_bot(_name_element, _output_file):
    _url = "https://www.hydac.com/de-de/nc/service/online-tools/betterfit.html?tx_hybetterfit_pi2%5Baction%5D=search&tx_hybetterfit_pi2%5Bcontroller%5D=Search&cHash=c662ac5f5387b650059f2ede4c291cec"
    # THis line produces an error message
    s = requests.Session()
    _headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"}
    _data = {"tx_hybetterfit_pi2[query]": _name_element}
    r = requests.post(_url, data=_data, headers = _headers)
    with open(_output_file, "w") as f: f.write(r.text)
    print(r.status_code)
    return(r.text)
def start_parce(_name_element):
    _output_file = "IDLE_HYDAC.html"
    _tmpvar = fg_list_bot(_name_element, _output_file)
Here is the error message
 ================= RESTART: E:\Python\Learning\start_parce.py =================
Traceback (most recent call last):
  File "E:\Python\Learning\start_parce.py", line 10, in <module>
    spisok = F_Hydac_POST.start_parce(_name_element)
  File "E:\Python\Learning\Parce_functions\F_Hydac_POST.py", line 81, in start_parce
    _tmpvar = fg_list_bot(_name_element, _output_file)
  File "E:\Python\Learning\Parce_functions\F_Hydac_POST.py", line 5, in fg_list_bot
    s = requests.Session()
NameError: name 'requests' is not defined
Quote
#2
the "second" module has no way to know what you would eventually import in the "first" module
you need to import requests in the second module
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  modifying variables in local or global space Skaperen 2 129 Aug-14-2019, 07:13 AM
Last Post: Skaperen
  PyMODINIT_FUNC and gcc hidden visibility jock 0 806 Feb-01-2018, 03:47 PM
Last Post: jock
  How is space of variables/functions/objects... called? j.crater 4 1,885 Dec-19-2016, 12:24 PM
Last Post: j.crater

Forum Jump:


Users browsing this thread: 1 Guest(s)