Collage

n. A piece of art made by sticking various different materials, aka PHENOMENA Magazine
Department
programming

programming

1. Install Geckodriver Go to the geckodriver releases page. Find the latest version of the driver for your platform and download it. For example: wget https://github.com/mozilla/geckodriver/releases/download/v0.35.0/geckodriver-v0.35.0-linux64.tar.gz Extract the file with: tar -xvzf geckodriver* Make it executable: chmod +x geckodriver Add the driver to your PATH so other tools can find it: sudo mv geckodriver /usr/local/bin/   2. Install Selenium pip install selenium   3. Sample code from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver import FirefoxOptions class TestView(View): def post(self, request, *args, **kwargs): query = kwargs["query"] url = f"https://www.vought.com/search?q={query}" opts = FirefoxOptions() opts.add_argument("--headless") browser = webdriver.Firefox(options=opts, executable_path=settings.SELENIUM_PATH) browser.get(url) html = browser.page_source sor = BeautifulSoup(html, "html.parser") target = sor.find("div", {"id": "x"}) text = target.text browser.quit() return JsonResponse({"result": text}, json_dumps_params={'ensure_ascii': False}, safe=False , content_type=u"application/json; charset=utf-8") * SELENIUM_PATH Examples Linux : /usr/local/bin/geckodriver Windows : B:\path\to\geckodriver-v0.30.0-win64\geckodriver.exe   Ref. How to install geckodriver in Ubuntu? I use Selenium in Python, I tried to run the webdriver function: default_browser = webdriver.Firefox() This Exception: WebDriverException: Message: 'geckodriver' executable needs to be in PATH. https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu Selenium and web driver setup for ubuntu In this article, I am going to explain selenium and web driver setup for ubuntu. https://medium.com/featurepreneur/selenium-and-web-driver-setup-for-ubuntu-4c41cb61cb6f
John Doe · Oct. 13, 2024, 3:36 a.m.
selenium BeautifulSoup
package com.phenomena.xxx.test.mail; import jakarta.mail.*; import jakarta.mail.internet.*; import java.util.*; public class MailSendTest { private static final String SMTP_HOST_NAME = "smtp.test.com"; //or simply "localhost" private static final String SMTP_AUTH_USER = "test"; // id private static final String SMTP_AUTH_PWD = "1234"; // pw private static final String emailMsgTxt = "Hell World"; private static final String emailSubjectTxt = "Title"; private static final String emailFromAddress = "test@phenomena.com"; // Add List of Email address to who email needs to be sent to private static final String[] emailList = {"contact@me.com"}; public static void main(String args[]) throws AuthenticationFailedException, MessagingException { MailSendTest smtpMailSender = new MailSendTest(); smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress); System.out.println("Sucessfully Sent mail to All Users"); } public void postMail( String recipients[], String subject, String message , String from) throws MessagingException, AuthenticationFailedException { boolean debug = false; // Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.port", "666"); //TLS Port props.put("mail.smtp.auth", "true"); //enable authentication props.put("mail.smtp.starttls.enable", "true"); //enable STARTTLS props.put("mail.debug", "true"); props.put("mail.smtp.ssl.enable", "true"); //Important Authenticator auth = new SMTPAuthenticator(); Session session = Session.getDefaultInstance(props, auth); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); } private class SMTPAuthenticator extends jakarta.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { String username = SMTP_AUTH_USER; String password = SMTP_AUTH_PWD; return new PasswordAuthentication(username, password); } } }   Ref. Got bad greeting from SMTP host: smtp.yandex.ru, port: 465, response: [EOF]] with root cause Yandex I use brand new spring boot project with next Maven dependency &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-star... https://stackoverflow.com/questions/63236701/got-bad-greeting-from-smtp-host-smtp-yandex-ru-port-465-response-eof-wit
John Doe · Aug. 22, 2024, 5:27 p.m.
Jakarta mail
Q The :) event at 11pm is correctly appearing on the correct date (8/1), but the :( event that starts 1 minute later appears to span across two days (8/1 - 8/2). See screenshot below.   A If you don't specify the end time, the default duration is 1 hour which makes it run into the next day: defaultTimedEventDuration - Docs | FullCalendar FullCalendar Demos Docs Support Getting Help Reporting Bugs Requesting Features Contributing Pricing Jul 12 — v6.1.15 Event Model Event Parsing Event Object Recurring Events RRule Plugin Event Data Parsing eventDataTransform defaultAllDay defaultAllDayEve https://fullcalendar.io/docs/defaultTimedEventDuration   ***** If the start time and the end time are the same, then the issue will also arise. Solutions: let calendar = new FullCalendar.Calendar(calendarEl, { initialView: 'dayGridMonth', //timeZone: 'Asia/Seoul', eventTimeFormat: { hour: '2-digit', minute: '2-digit', hourCycle: 'h24' }, defaultTimedEventDuration: '00:00', events: [ { id: 'a', title: 'my event', "start": "2024-07-09T23:02:21", "end": "2024-07-09T23:02:21", //"start": "2024-07-09T23:02:20+0900", //"end": "2024-07-09T23:02:21+0900", } ] });   OR   let calendar = new FullCalendar.Calendar(calendarEl, { initialView: 'dayGridMonth', //timeZone: 'Asia/Seoul', eventTimeFormat: { hour: '2-digit', minute: '2-digit', hourCycle: 'h24' }, //defaultTimedEventDuration: '00:00', events: [ { id: 'a', title: 'my event', //"start": "2024-07-09T23:02:21", //"end": "2024-07-09T23:02:21", "start": "2024-07-09T23:02:20+0900", "end": "2024-07-09T23:02:21+0900", } ] });   Ref. Events after 11pm appear to span two days · Issue #5008 · fullcalendar/fullcalendar See: https://jsfiddle.net/412qh7zx/5/ The :) event at 11pm is correctly appearing on the correct date (8/1), but the :( event that starts 1 minute later appears to span across two days (8/1 - 8/2).... https://github.com/fullcalendar/fullcalendar/issues/5008
John Doe · July 30, 2024, 8:36 p.m.
fullcalendar
Error File "/home/kuba/.virtualenvs/VeeU/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in apply_converters 779. value = converter(value, expression, self.connection, self.query.context) File "/home/kuba/.virtualenvs/VeeU/lib/python3.5/site-packages/django/db/models/functions/datetime.py" in convert_value 181. "Database returned an invalid datetime value. " ValueError: Database returned an invalid datetime value. Are time zone definitions for your database installed?   Solution 1. Linux contact@me:~$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql contact@me:~$ mysql -u root -p -e "flush tables;" mysql 2. Windows 1) Download posix timezone sql from https://dev.mysql.com/downloads/timezones.html 2) Do not move anything, just open this sql file in MySQL Workbench and add USE mysql; to the first line. 3) Run this file and that's it   * How to run SQL script in MySQL? 1. If you’re at the MySQL command line mysql> you have to declare the SQL file as source. mysql> source \home\user\Desktop\test.sql; 2. CMD   Ref. Django Mysql Database returned an invalid datetime value I have a Django app. I am using MySql server running in docker container as a database. After just moved to a custom User model. Now i am getting those errors: Environment: Request Method: GET Req... https://stackoverflow.com/questions/40792628/django-mysql-database-returned-an-invalid-datetime-value Database returned an invalid datetime value. Are time zone definitions for your database installed? i tried to TruncDay in django to turn date into day format , i use mysql version 8.0 with windows 10 this my settings.py TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True date = m... https://stackoverflow.com/questions/62581502/database-returned-an-invalid-datetime-value-are-time-zone-definitions-for-your [DB] MySQL SQL파일 실행 및 백업 ■ SQL파일 실행 1. 프롬프트(cmd) 환경 예시) mysql -u(유저명) -p < sql파일명.sql mysql -uroot -p < testFile.sql 1) testFile.sql 내용 확인 2) 프롬프트(cmd)에서 실행 2. MySQL 접속 환경 예시) source sql파일명.sql source C:\MySQL\testFile.sql ■ SQL파일로 DataBase 백업 ※ 프롬프트(cmd) 환경 예시) mysqldump -u(유저명) https://hyunmin1906.tistory.com/103   * MariaDB에서 root 암호 인증 방식이 먹히지 않는 이유(feat. unix_socket) [B급 프로그래머] MariaDB에서 root 암호 인증 방식이 먹히지 않는 이유(feat. unix_socket) "컴퓨터와 책에 대한 블로그입니다." https://jhrogue.blogspot.com/2020/02/b-mariadb-root-feat-unixsocket.html MariaDB; 인증(Authentication) 문제. – 바깥 세상으로.. (As a kite by then) Skip to content 바깥 세상으로.. (As a kite by then) Search for: × Menu 첫머리 이곳은? 以前 記錄 記憶 (egloos) 주저리주저리 Prince & New Power Generation – Diamonds & Pearls 갑자기, Prince. Tears for Fears: The Tipping Point Pat Metheny: Road to the Sun 김태은/오경희/정민아 : 산조的 감각 Pat Meth https://www.nemonein.xyz/2019/07/2254/
John Doe · June 10, 2024, 7:22 p.m.
django SQL
Neither of above helped in my case - IP connection to http works as expected but https was redirecting to alphabetically first https virtual site. What was working witn nginx below 1.19.4 was to add null certificate to block: server { listen 80 default_server; listen [::]:80 default_server; listen 443 default_server; listen [::]:443 default_server; ssl_certificate /etc/ssl/null.crt; ssl_certificate_key /etc/ssl/null.key; server_name ""; return 444; }   Certificte can be generated with empty CN so you need no worry about fill it. sudo openssl req -x509 -newkey rsa:2048 -days 10000 -nodes -subj "/C=US/ST=Florida/L=XXXXX/O=Foo Inc./OU=IT/CN=X" -keyout null.key -out null.crt   Then http/https returns 444 (ERR_EMPTY_RESPONSE), in different configurations https returns ERR_HTTP2_PROTOCOL_ERROR with your null certificate which is also fine to show there is nothing there. For nginx 1.19.4 it is simpler. It introduced ssl_reject_handshake on | off (http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_reject_handshake) you can replace certificates 'stuff' with: server { listen 80 default_server; listen [::]:80 default_server; listen 443 default_server; listen [::]:443 default_server; ssl_reject_handshake on; server_name ""; return 444; }   And now you get http 444 (ERR_EMPTY_RESPONSE) and for https ERR_SSL_UNRECOGNIZED_NAME_ALERT. No null certificates are needed.   Ref. how to disable direct access to a web site by ip address I have a website on a VPS. The issue I am having is that when I enter the IP of the server, it links to the website. Even when entering mail.domain.com, it does the same thing. How do I disable t... https://stackoverflow.com/questions/29104943/how-to-disable-direct-access-to-a-web-site-by-ip-address OpenSSL: A problem with Field Name abbreviations? I am trying to create a new private key and CSR file for a colleague with some provided details: C = US S = Florida L = XXXXX O ... https://stackoverflow.com/questions/55541601/openssl-a-problem-with-field-name-abbreviations
John Doe · Nov. 28, 2023, 9:14 p.m.
nginx ssl
SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. When client receives the server’s certificate, it begins chaining that certificate back to its root. It will begin by following the chain to the intermediate that has been installed, from there it continues tracing backwards until it arrives at a trusted root certificate. If the certificate is valid and can be chained back to a trusted root, it will be trusted. If it can’t be chained back to a trusted root, the browser will issue a warning about the certificate.   Common issues :  CERTIFICATE_VERIFY_FAILED [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate. HTTPSConnectionPool(host='oriel.com' , port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))   How to fix it :  We will have several ways to fix this issue in this article.  We will skip the SS certificate check in the first three solutions.  For the fourth solution, we are going to install the latest CA certificate from certifi. Common Quick Fixes for All OS : import ssl import certifi from urllib.request import urlopen request = "https://nd-123-456-789.p2pify.com/901c7d18b72538fd3324248e1234" urlopen(request, context=ssl.create_default_context(cafile=certifi.where()))   Or we can try it in several ways as per in below articles 1. Create unverified context in SSL import ssl context = ssl._create_unverified_context() urllib.request.urlopen(req,context=context)   2. Create unverified https context in SSL import ssl ssl._create_default_https_context = ssl._create_unverified_context urllib2.urlopen(“https://google.com”).read()   3. Use requests module and set ssl verify to false requests.get(url, headers=Hostreferer,verify=False) * It's not recommended to use verify=False in your organization's environments. This is essentially disabling SSL verification. Sometimes, when you are behind a company proxy, it replaces the certificate chain with the ones of Proxy. Adding the certificates in cacert.pem used by certifi should solve the issue. I had similar issue. Here is what I did, to resolve the issue - Find the path where cacert.pem is located - Install certifi, if you don't have. Command: pip install certifi import certifi certifi.where() C:\\Users\\[UserID]\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\certifi\\cacert.pem Open the URL on a browser. Download the chain of certificates from the URL and save as Base64 encoded .cer files. Now open the cacert.pem in a notepad and just add every downloaded certificate contents (---Begin Certificate--- *** ---End Certificate---) at the end.   4. Update SSL certificate with PIP It is likely that the SSL certificate issued by the server is not trusted on your client. To fix this, you can either use a trusted certificate from a recognized certificate authority on the API end, or add the certificate authority from your API to your client. if the error stay, try these commands to update your SSL certificate libs With PIP. All we would have to do is to update our SSL certificate directory with the following piece of code: if older version of python3 pip install –upgrade certifi if newer version of python3 python -m pip install --upgrade certifi What this command does is update our system’s SSL certificate directory. This will ensure that your client has the latest version of the library, which includes a set of trusted root certificates that may be needed to verify SSL certificates.   5. Update SSL certificate with certifi (MacOS only) All we would have to do is to run command with the following piece of code: - Press "command + space" button or open Spotlight - type "Install Certificates.command" What this command does is update our system’s SSL certificate directory for MacOS.   https://support.chainstack.com/hc/en-us/articles/9117198436249-Common-SSL-Issues-on-Python-and-How-to-Fix-it Unable to get local issuer certificate when using requests here is my code import requests; url='that website'; headers={ 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Language':'zh-CN,zh;q=0.... https://stackoverflow.com/questions/51925384/unable-to-get-local-issuer-certificate-when-using-requests HTTPSConnectionPool: Max retries exceeded with URL (Caused by SSLError) I am trying to make an HTTPS request to a URL using Python requests library and certifi library as follows: import certifi url = 'https://10.0.0.39:4455/api/cars' response = requests.get(url, verify= https://stackoverflow.com/questions/75913891/httpsconnectionpool-max-retries-exceeded-with-url-caused-by-sslerror CERTIFICATE_VERIFY_FAILED error Python Django error: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)&gt; Exception Location: /usr/lib/python3.8/u... https://askubuntu.com/questions/1401379/certificate-verify-failed-error Why do I receive 'unable to get local issuer certificate (_ssl.c:997)' When sending a request to a specific URL I get an SSL error and I am not sure why. First please see the error message I am presented with: requests.exceptions.SSLError: HTTPSConnectionPool(host='di... https://stackoverflow.com/questions/70977935/why-do-i-receive-unable-to-get-local-issuer-certificate-ssl-c997 SSLError: max retries exceeded with url error? How to fix this? I am attempting to scrape text off of websites, and I am using the requests module to do so. With the given code (Facebook as an example here) requests.get('http://facebook.com') I receive back the https://stackoverflow.com/questions/72188582/sslerror-max-retries-exceeded-with-url-error-how-to-fix-this
John Doe · Aug. 29, 2023, 8:15 p.m.
ssl python
John Doe · Aug. 6, 2023, 8:52 a.m.
The spring boot error Path with “WEB-INF” or “META-INF” occurs when the jsp page url is invoked and the tomcat jasper dependency is not configured in the application. The jsp files are compiled and rendered using the tomcat embedded jasper maven dependency. If the maven dependency is not configured in the spring boot application, the “path with WEB-INF or META-INF” error will be shown in the console. In the spring boot application, when you access a jsp page in browser, it shows “Whitelabel Error Page, There was an unexpected error (type=Not Found, status=404).” error in the browser. The exception to this is “HTTP 404 – page not found”. In the spring boot console log, the error is shown as ‘Path with ‘WEB-INF’ or ‘META-INF’. The ResourceHttpRequestHandler class will throw the error as “o.s.w.s.r.ResourceHttpRequestHandler : Path with “WEB-INF” or “META-INF”:”   Exception The exception stack trace will be shown below. This will be displayed in the console when a jsp page is invoked. 2019-10-03 13:17:57.140 WARN 3200 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/helloworld.jsp] 2019-10-03 13:17:57.154 WARN 3200 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/error.jsp]   How to reproduce this issue This error can be replicated in the mvc spring boot application. Follow the steps below to reproduce this issue. Create a spring boot mvc project in the Spring Tool Suite editor. Set up the jsp folder in the application.properties file as shown below. application.properties spring.mvc.view.prefix:/WEB-INF/jsp/ spring.mvc.view.suffix:.jsp Create a rest controller class to configure and invoke a url that will map to jsp file. Create a method in the controller class and configure the request mapping url to invoke. Configure a jsp file in the method that will be rendered when the url is invoked. HelloWorldController.java package com.yawintutor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloWorldController { @RequestMapping("/HelloWorld") public ModelAndView firstPage() { return new ModelAndView("helloworld"); } } Create a jsp file that is configured in the controller class. In this example, a helloworld.jsp file is created in the src / main / webapp / WEB-INF / jsp / folder. The jsp file contains a simple message. src/main/webapp/WEB-INF/jsp/helloworld .jsp <h1>Welcome to Hello World!</h1> Open a browser and call the url as “http://localhost:8080/HelloWorld”. This url should invoke firstPage method in HelloWorldController class. The model view is configured with helloworld. the file in src/main/webapp/WEB-INF/jsp/helloworld.jsp should be rendered.   Root Cause The jsp path resolving class is available in tomcat jasper package. The dependency of tomcat jasper is not added in pom.xml. So the jsp path is not resolved by spring boot application   Solution The dependent jars are available in tomcat jasper. Add tomcat jasper dependency in pom.xml file <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>   Ref. Path with “WEB-INF” or “META-INF” – Yawin Tutor Skip to content Home Java C Spring Boot Issues Spring Boot Python Database Others Technicals Contact Us Home Java C Spring Boot Issues Spring Boot Python Database Others Technicals Contact Us Path with “WEB-INF” or “META-INF” The spring boot error Path wi https://www.yawintutor.com/warn-3200-path-with-web-inf-or-meta-inf/
John Doe · Aug. 3, 2023, 9:02 a.m.
java spring
  • 1 (current)
  • 2
  • 3
  • 4
  • 5