1

My goal is to launch my script from windows task scheduler.

However, I think the scheduler uses CMD to launch the code - and the CMD does not want to run my script!

When I run the script from either Anaconda prompt or Spyder, the script launches perfectly. The command that works in Anaconda prompt, but not in CMD, is: C:\Users\ola_k\Anaconda3\envs\myvirtenv\python.exe C:\Users\ola_k\Desktop\myfilewithscript\script.py

When I try to run the above command in CMD, it unfortunately provides me an error

urlopen error unknown url type: https.

I have tried to set PATH variables from my anaconda environment. I have also tried creating .BAT files, but none seem to work.

I have read many posts on stackexhange about urlopen errors, but none seem to answer my question: why can I run it from Anaconda prompt and Spyder, but not with CMD? Especially since I have set the python installed from anaconda to path variables.

Here is a snippet from my script:

import smtplib 
from email.mime.text import MIMEText 
from bs4 import BeautifulSoup as soup
from urllib.request import Request, urlopen
import time
from datetime import date, timedelta
import re


CPV = "73000000" 
req = "https://doffin.no/Notice?query=&PageNumber=1&PageSize=100&OrderingType=0&OrderingDirection=1&RegionId=&CountyId=&MunicipalityId=&IsAdvancedSearch=false&location=&NoticeType=&PublicationType=&IncludeExpired=false&Cpvs="+CPV+"&EpsReferenceNr=&DeadlineFromDate=&DeadlineToDate=&PublishedFromDate=&PublishedToDate="

urlRequest = []
urlRequest.append(Request(req, headers={"User-Agent": "Mozilla/5.0"}))
webpage = urlopen(urlRequest[0]).read() 
page_soup = soup(webpage, "html.parser")

The code does work when I run it from Spyder or Anaconda prompt, so I think the code itself is fine.

NOTE: If there are other solutions, e.g. how I can run Anaconda Prompt from task scheduler, that would also solve my problem.

Ola
  • 81
  • 1
  • 8

1 Answers1

0

I solved the problem by reinstalling Anaconda3 and adding it to my path directly from the options (even though it is not recommended).

Ola
  • 81
  • 1
  • 8