current goal is to import code from 1 file and run it in another but i getting this error
Job "runF5 (trigger: interval[1 day, 0:00:00], next run at: 2023-01-31 00:24:00 PKT)" raised an exception
Traceback (most recent call last):
File "E:\pyton\Lib\site-packages\apscheduler\executors\base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "e:\completed zameen project\combined.py", line 11, in runF5
m5.runF5(playwright)
File "e:\completed zameen project\m5.py", line 131, in runF5
browser = playwright.chromium.launch(headless=False, slow_mo=600)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'playwright' has no attribute 'chromium'
code in file 1
i intend to import the function runF5 from file 1 to file 2
from playwright.sync_api import Playwright, sync_playwright, expect
#import playwright
import random
import time
import sys
import pyautogui
def runF5(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False, slow_mo=600)
context = browser.new_context()
page = browser.new_page()
page.goto('https://www.google.com/', timeout=0)
#time.sleep(1)
code in file 2 which is importing the code from file 1
import playwright
import schedule
import datetime
import time
import m5
import schedule
from apscheduler.schedulers.background import BackgroundScheduler
def runF5():
# code to run at 03:30
m5.runF5(playwright)
scheduler = BackgroundScheduler()
scheduler.add_job(runF5, 'interval', days=1, start_date='2022-01-01 03:31:00', timezone='Asia/Karachi')
scheduler.start()
# Keep the program running
while True:
pass
i was expected at the given time the code will run and open google but i keeping getting the error
i always change the time so the codes runs 2mins from now- for testing
Related
app.py file code:
import webbrowser
import time
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import certifi
import json
def get_jsonparsed_data(url):
"""
Receive the content of ``url``, parse it as JSON and return the object.
Parameters
----------
url : str
Returns
-------
dict
"""
response = urlopen(url, cafile=certifi.where())
data = response.read().decode("utf-8")
return json.loads(data)
url = ("https://financialmodelingprep.com/api/v3/quote/AAPL,FB?apikey=d099f1f81bf9a62d0f16b90c3dc3f718")
print(get_jsonparsed_data(url))
country = get_jsonparsed_data(url)
count = 0
for result in country:
if count == 0:
header = result.keys()
for head in header:
html_content = f"<div> {head} </div>"
count += 1
with open("index.html", "w") as html_file:
html_file.write(html_content)
print("Html file created successfully !!")
time.sleep(2)
webbrowser.open_new_tab("index.html")
passenger_wsgi.py file code:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.application
Error:
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Traceback (most recent call last):
File "/home/stockpee/staging/passenger_wsgi.py", line 9, in <module>
application = wsgi.application
AttributeError: module 'wsgi' has no attribute 'application'
Hi,
Everyone, I am new in Python. I have develop a basic application on my local machine. But when I deployed it on A2Host hosting server. I am facing above error when I run my application in web browser.
Is anyone help me to fix above issue. I will be very thankful for that person.
I will applogize in advance for my brief answer. But it has to do with the fact that you have not established a whisky app.
You need to make sure in your main application file app.py you establish your application.
def app(environ, start_response):
pprint("whoo hooo. ")
I hope this helps.
I want to run a Tor session on a headless computer and I'm using the code from https://github.com/webfp/tor-browser-selenium/blob/master/examples/headless.py
from argparse import ArgumentParser
from tbselenium.tbdriver import TorBrowserDriver
from tbselenium.utils import start_xvfb, stop_xvfb
from os.path import join, dirname, realpath
def headless_visit(tbb_dir):
out_img = join(dirname(realpath(__file__)), "headless_screenshot.png")
# start a virtual display
xvfb_display = start_xvfb()
with TorBrowserDriver(tbb_dir) as driver:
driver.load_url("https://check.torproject.org")
driver.get_screenshot_as_file(out_img)
print("Screenshot is saved as %s" % out_img)
stop_xvfb(xvfb_display)
def main():
desc = "Headless visit and screenshot of check.torproject.org using XVFB"
parser = ArgumentParser(description=desc)
parser.add_argument('tbb_path')
args = parser.parse_args()
headless_visit(args.tbb_path)
if __name__ == '__main__':
main()
But it raises this error:
Traceback (most recent call last):
File "test.py", line 28, in <module>
main()
File "test.py", line 24, in main
headless_visit(args.tbb_path)
File "test.py", line 10, in headless_visit
xvfb_display = start_xvfb()
File "/usr/local/lib/python3.8/dist-packages/tbselenium/utils.py", line 33, in start_xvfb
xvfb_display = Display(visible=0, size=(win_width, win_height))
NameError: name 'Display' is not defined
I'm using:
python 3.8.5
geckodriver v 0.17.0
tor browser v 10.0.5
This is caused by a missing python package 'pyvirtualdisplay'
solution:
pip3 install pyvirtualdisplay
cause:
If you look at the utils.py file referenced in the error you will find that the import of pyvirtualdisplay is nested in a try block with an exception handler that silently passes. The comment suggests it is only needed for tests but that is obviously not true in our case.
I am writing a simple program to check how multiprocessing works in Python 3. And I am testing with code that is similar to what is available in Python 3.6 documentation.
However when running the code I am facing an ImportError and not able to move forward.
I have also observed some confusing outputs.
When executing the code in PYthon IDE, it does not throw an error.
from multiprocessing import Process
However, if i execute it on Linux prompt, it throws an error.
My complete code is
from multiprocessing import Process
def worker():
print("working")
if __name__ == '__main__':
jobs = []
p = Process(target=worker)
jobs.append(p)
p.start()
print(jobs)
Traceback (most recent call last):
File "C:/Users/AASRITHA/PycharmProjects/untitled/multiprocessing.py", line 1, in <module>
from multiprocessing import Process
File "C:\Users\AASRITHA\PycharmProjects\untitled\multiprocessing.py", line 1, in <module>
from multiprocessing import Process
ImportError: cannot import name 'Process'
I can't run my script I'm using python3 and I install pyrebase and his dependencies
I got this below exception when I try to run my script on linux ubuntu
Traceback (most recent call last):
File "scrapping2fb.py", line 9, in <module>
import pyrebase
File "/usr/local/lib/python3.4/dist-packages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/usr/local/lib/python3.4/dist-packages/pyrebase/pyrebase.py", line 19, in <module>
from requests.packages.urllib3.contrib.appengine import is_appengine_sandbox
Can some one help me
Thank you
The script that i try to run
from urllib.request import urlopen ,URLError,HTTPError,Request
from socket import timeout
from bs4 import BeautifulSoup
from time import sleep
import mysql.connector
from datetime import datetime
import pyrebase
def is_exist_firebase_db_AR(siteName,title):#(siteName,title):
global config
global email
global password
firebase = pyrebase.initialize_app(config)
db=firebase.database()
auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email, password)
all_items = db.child("items_ar").get(user['idToken'])
if(all_items.each() is not None):
for item in all_items.each():
if(siteName in item.val().get("nomSite") and title in item.val().get("titre")):
return 1
return 0
This is a problem with the pyrebase package.
Since commit 8e17600ef60de4faf632acb55d15cb3c178de9bb which went into v2.16.0, requests no longer bundle urllib3.
The package pyrebase is relying on this implementation detail, and, like all things that rely on implementation details eventually do, was broken.
I'm trying to run the following code, which was directly copied from the documentation:https://docs.python.org/dev/library/concurrent.futures.html#module-concurrent.futures :
import executor
import concurrent.futures
import time
def wait_on_b():
time.sleep(5)
print(b.result()) # b will never complete because it is waiting on a.
return 5
def wait_on_a():
time.sleep(5)
print(a.result()) # a will never complete because it is waiting on b.
return 6
executor = ThreadPoolExecutor(max_workers=2)
a = executor.submit(wait_on_b)
b = executor.submit(wait_on_a)
And I get the following output:
Traceback (most recent call last):
File "test1.py", line 16, in <module>
executor = ThreadPoolExecutor(max_workers=2)
NameError: name 'ThreadPoolExecutor' is not defined
I'm assuming that I forgot to import something, but I don't know.
Either use from concurrent.futures import ThreadPoolExecutor instead of import concurrent.futures, or leave the import as-is and use executor = concurrent.futures.ThreadPoolExecutor(maxworkers=2).
Also note that the example code you copied is designed to deadlock, so it's not going to work properly once you fix the import issue.